I am trying to run a back script that I wrote that I have placed in the /srv directory on my xubuntu machine.

But when I try to run it, it errors with the following...

user@linuxbox:/srv$ sudo ./backup.sh 
sudo: unable to execute ./backup.sh: No such file or directory

The contents of my backup.sh script are as follows...

rsync --update -raz --progress ./git  '/media/user/New Volume/BACKUP'

EDIT: I did flip the executable bit using chmod.

Here is the permissions...

-rwxr-xr-x 1 root root 81 Mar 18 17:16 /srv/backup.sh

EDIT: Apparently another running instance of nano is editing my file. But I did a restart of the PC, so not sure how that persisted. Could this be the problem? This happens when I try to edit in nano.

File backup.sh is being edited (by root with nano 2.5.3, PID 14039); continue? 

When I try to kill that process by the PID, it says "No such process"

  • 1
    Executable bit is missing. – phk Mar 18 '17 at 23:08
  • 1
    ...and that there are no non-printable characters in the filename? Trailing space, maybe? – Jeff Schaller Mar 18 '17 at 23:11
  • 2
    Also ls -l /bin/sh – Jeff Schaller Mar 19 '17 at 1:07
  • 3
    head -n 1 backup.sh|od -t x1 and look for 0d – Michael Homer Mar 19 '17 at 4:41
  • 2
    @G-Man "No such file or directory" when running scripts on UNIX is typical for scripts with Windows newlines. FWIW. – Satō Katsura Mar 20 '17 at 8:54

The first thing I would do is use the full path instead of relative, and check to make sure you have "execute" bit set. If you can't do an ls /srv/backup.sh then you know it's a name/path issue. Likewise if no execute bit set, even root will not be able to execute it.

i.e. sudo /srv/backup.sh

| improve this answer | |
  • when I did ls command it listed backup.sh in green. Does that mean the execute bit is set correctly? – ScottF Mar 19 '17 at 1:35
  • Per Jeff and Terdon's request, to verify do a long listing ls -l /srv/backup.sh so we can see the full permissions. If you don't see an "x" listed in the permissions then that would be a no. – Sending_Grounds Mar 19 '17 at 1:40
  • I updated with new info. – ScottF Mar 19 '17 at 1:42

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