0
votes

I have a bash script that copies over files from local to remote server using scp. Once all of the transfer is done, I run chmod command over the ssh to open up all of the permission. The problem is that it intermittently works and does NOT chmod 777 properly all the time. Any way I can verify that chmod command executed definitely (maybe using return code or something)? I do have my ssh keys setup so I do NOT need to enter password upon doing ssh or scp. Below is the snippet of my code

#copy over the files from local machine to remote server

scp file1.txt file2.txt file3.txt 10.111.222.333:/home/user1/fileDir/

#open up the permissions on the remote server

ssh -qX 10.111.222.333 chmod -R 777 /home/user1/fileDir
1
The exit code from the ssh command should reflect that of the chmod command -- that is, if chmod gets an error, ssh should return a nonzero code as well.Gordon Davisson

1 Answers

1
votes

You could try: ssh server "chmod 755 file |echo $?"

which would return 0

The |echo $? is checking the return code for the command ran.