sh: ... No such file or directory

Discussion in 'Programming/Scripts' started by frosty, Oct 13, 2012.

  1. frosty

    frosty New Member

    Hello there,

    While trying to invoke my test shell script via crontab, I am bumping into "sh: my_shell_script.sh: No such file or directory" error message. The same script however executes just fine when invoked manually from the Putty ssh terminal, like "./my_shell_script.sh".

    The directory where the script resides exists, has 755 permissions set recursively and I can access it/write into it via my FTP client without any problem.

    The script my_shell_script.sh itself is just a test script outputting "Hello world":

    #!/bin/bash
    echo "Hello world"

    The invoking this shell script crontab crontab.txt file goes as follows:

    MAILTO=my_email_address@abc.com
    30 * * * * sh ./my_shell_script

    I know that the cronjob to invoke the my_shell_script.sh gets created as running "crontab -l" plus receiving emails proves.

    I've written it under my Ubuntu Linux using Kate editor, so it doesn't contain any Windows generated unnecessary characters. The folder where this shell script resides is 755.

    I am not sure if it would help, but I've run echo %PATH and it's output is:

    /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/opt/dell/srvadmin/bin

    Also, this scenario occurs on my remote hosting account which I am allowed to access via SSH.

    Looking forward to hearing from honourable gurus.

    Cheers

    Alex
     
  2. falko

    falko Super Moderator

    Please use the full path to the script in your cron line.
     
  3. frosty

    frosty New Member

    Full path to a shell script

    Thank you for your answer, falko.

    I've tried:

    MAILTO=my_email_address@abc.com
    30 * * * * sh /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/opt/dell/srvadmin/bin/my_shell_script

    and

    MAILTO=my_email_address@abc.com
    30 * * * * sh /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/opt/dell/srvadmin/bin/.my_shell_script

    (just playing with keeping/not keeping dot in front of the shell script name at the end of the path)

    both instances - no joy: the same

    "sh: /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/opt/dell/srvadmin/bin/backup/democronjobs/my_shell_script: No such file or directory"

    and

    "sh: /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/opt/dell/srvadmin/bin/backup/democronjobs/.my_shell_script: No such file or directory"

    error messages in my mailbox.

    Cheers,

    Alex
     
  4. till

    till Super Moderator

    Run the command:

    which sh

    to get the full path of the sh interpreter. The replace "sh" in your cron commands with the full path to the sh interpreter.
     
  5. falko

    falko Super Moderator

    /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/opt/dell/srvadmin/bin/backup/democronjobs/my_shell_script is no path.

    I guess you mean /opt/dell/srvadmin/bin/backup/democronjobs/my_shell_script so try that one.
     
  6. frosty

    frosty New Member

    Testing /opt/dell/srvadmin/bin/backup/democronjobs/my_shell_script

    Thank you for your quick reply.

    the "which sh" produced /bin/sh

    I've run my cronjob.txt file with the suggested path /opt/dell/srvadmin/bin/backup/democronjobs/my_shell_script as

    MAILTO=abc@abc.com
    57 * * * * /bin/sh /opt/dell/srvadmin/bin/backup/democronjobs/.my_shell_script

    as well as

    MAILTO=abc@abc.com
    57 * * * * /bin/sh /opt/dell/srvadmin/bin/backup/democronjobs/my_shell_script

    The same "No such file or directory" error message persists.

    Cheers,

    Alex
     
    Last edited: Oct 15, 2012
  7. CSARLAB

    CSARLAB ISPConfig Developer

    hi there

    are you sure you using right path for corn?
    check the path and try again everything is alright
     
  8. frosty

    frosty New Member

    thank you for chipping in.

    how can I find the proper path to my cron jobs? as I said a few posts above, I've run "echo $PATH" and got /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/opt/dell/srvadmin/bin, not really sure what it is and how to use it.

    Cheers,

    Alex
     
    Last edited: Oct 16, 2012
  9. falko

    falko Super Moderator

    What are the outputs of

    Code:
    ls -la /opt/dell/srvadmin/bin/backup/democronjobs/my_shell_script
    and
    Code:
    updatedb
    locate my_shell_script
    ? (Make sure you replace my_shell_script with the actual name of the script.)
     
  10. frosty

    frosty New Member

    Output

    Just drilling with "ls" into the /opt/ a have found that this folder contains only "suphp" subfolder which in turn contains only "sbin".

    No wonder running the ls /opt/dell/ already produced "No such file or directory" error message.

    updatedb and locate my_shell_script thrown out "command not found".

    Cheers,

    Alex
     
  11. CSARLAB

    CSARLAB ISPConfig Developer

    which distribution you using?
    every linux distribution have different commands
     
  12. frosty

    frosty New Member

    Which version

    What Linux distro are we talking about? If it's about my desktop, then I am on Ubuntu 10.04. Or are you asking about Linux system of my hosting where I am trying to work with my shell scripts?

    Cheers,

    Alex
     
  13. CSARLAB

    CSARLAB ISPConfig Developer

    Your hosting where you trying this shell script mate that i am asking:)
     
  14. aFoP

    aFoP New Member

    Hi,
    I would not specify /bin/sh in the cron job itself ...

    What about
    If in the script itself you specify #!/bin/bash or #!/bin/sh it should run (as root) without problems.
    Or did you try to add below 2 lines into the crontab before the above line?

     
    Last edited: Apr 19, 2013
  15. frosty

    frosty New Member

    Thank you

    Thank you for your answer, aFoP and to the rest who's help me in this thread. Although I've already moved from that project, I still do appreciate your reply.

    To mods: Please feel free to close this thread now.

    Have a nice weekend eveyone ;)

    Cheers,

    Alex
     
    Last edited: Apr 19, 2013

Share This Page