I am attempting to write a script to run a script, but before I run the script I want to check if it is dos or unix format and convert it accordingly. Here is what I have so far:
spawn ssh root@login
expect "assword:"
send "myPass\r"
expect "#"
send "cd /myDir\r"
expect "#"
if head -1 *.sh | grep $'[\x0D]' >/dev/null #check to see if dos or unix
then #if dos then convert to unix and change permissions
dos2unix *.sh
chmod 777 *.sh
else #else execute script
./*.sh
fi
expect "#"
Am I allowed to include if statement in the middle of the expect script like this? Also how can I execute multiple command after the if statement( the dos2unix and chmod).