I have a shell script in one server (Ubuntu) say server1, in which i create a folder in other server say server2. But the command for create directory is not working. Folder is not creating in server2 when i run the script. But if i run the script directly from commandline it creates folder in the server2. Here is the script file :


sshpass -p 'xyz' ssh server2@xx.xx.xx.xx '[ -d /var/www/html/Database/Backup/Backups/05-08-2018 ]'

if [[ $? -eq 0 ]]
  echo 'Directory exists'
  echo 'Not exists! Creatting'
  sshpass -p 'xyz' ssh server2@xx.xx.xx.xx  "mkdir -p /var/www/html/Database/Backup/Backups/05-08-2018"

What might be the problem here? Can anyone look into it and help me in resolving this.


By removing sudo while calling the script helped me resolving the issue. It is working without sudo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.