0

As the title states, I have a shell script written then transfer the file to RHEL6 or 7. I give the script executable permission and run. It outputs a bunch of errors.

If I vi backup.sh, copy script text, then :wq and chmod +x it runs perfectly.

I've tried filezilla, and WinSCP. I tried changing the Transfer settings to binary. I've tried notepad++ and notepad.exe. Nothing works except for creating the script on the actual server.

This issue is not isolated to just me. Coworkers experience the same result on their machines.

Any ideas?

# !/bin/bash
# A backup script that copies important files to a backup folder called 
#`hostname`_'date +%Y-%m-%d`;
# Example: BrianAA_2017-10-11

path=/tmp/`hostname`_`date +%Y-%m-%d`
backup=$path

echo "Making backup directory $backup now"
mkdir -p -m777 $path

#Copy
cp -pr /opt/advatar/etc/advatar.conf $backup
cp -pr /etc/hosts $backup
cp -L /etc/rc.local $backup
cp -pr /etc/sysconfig/network $backup
cp -pr /etc/ntp.conf $backup
cp -pr /etc/sysconfig/ntpd $backup

#Looks for only "ifcfg-*" in /etc/sysconfig/network-scripts/
rsync -a --include='ifcfg-*' --exclude '*' /etc/sysconfig/network-scripts/ 
$backup

#iptables || firewalld
cat /etc/redhat-release | egrep -q '6.*'
if [ "$?" = "0" ]; then
    cp -pr /etc/sysconfig/iptables $backup
    cp -pr /etc/sysconfig/iptables-config $backup
fi
cat /etc/redhat-release | egrep -q '7.*'
if [ "$?" = "0" ]; then
    cp -pr /etc/firewalld $backup
fi

#prints output of network information to txt files in $backup
route > $backup/route.txt
ip a s > $backup/ifconfig.txt

#Looks for external mount points and searches by type: cifs, nfs, rpc,
#then copies necessary files to $backup if present in mount
mount | egrep -q 'cifs|nfs|rpc'
if [ "$?" = "0" ]; then
mount > $backup/mount.txt
    cp -pr /etc/auto.cifs $backup
    cp -pr /etc/auto.master $backup
    cp -pr /root/.smbauth $backup
    cp -pr /etc/fstab $backup
else
    echo "No Network Mount"
fi

[root@IFS-AA6 tmp]# ./back.sh
: command not found
: command not found
nowng backup directory /tmp/IFS-AA6_2017-10-26
: command not found
: command not found
ERROR: destination must be a directory when copying more than 1 file
rsync error: errors selecting input/output files, dirs (code 3) at main.c(542) [receiver=3.0.6]
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600 [sender=3.0.6]
: command not found
./back.sh: line 50: syntax error near unexpected token fi' ./back.sh: line 50:fi'
[root@IFS-AA6 tmp]#

1
  • 1
    Make sure, when you transfer the file, that the line endings are LF only, not CRLF. The : command not found are most likely \r: command not found for the blank lines with \r\n line endings Commented Oct 26, 2017 at 19:49

1 Answer 1

0

Make sure, when you transfer the file, that the line endings are LF only, not CRLF. The : command not found are most likely \r: command not found for the blank lines with \r\n line endings – glenn jackman 16 mins ago

@glennjackman thanks so much that was it

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .