Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32

Thread: at command launches script

  1. #1
    Join Date
    Aug 2006
    Beans
    428

    at command launches script

    I want to use "at" to launch an .sh file.

    For example
    Code:
    at now + 2 hours a.sh
    .

    I have used the script in question forever so there is no doubt that it works.

    I have tried a variety of commands and searched on the 'net for "at" help ... and have gotten nowhere.

    Can anyone help?

    TIA

  2. #2
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: at command launches script

    https://blog.jdpfu.com/2011/03/04/schedule-jobs-with-at shows how.

    You cannot trust the PATH to find a.sh. Specify the location exactly. That can be either with an absolute path to the file or with a relative path. Your choice.

    Code:
    at -f ./a.sh  now + 2 hours 
    at -f ~/bin/a.sh  now + 2 hours 
    at -f /usr/local/bin/a.sh  now + 2 hours
    If you must trust the PATH, then you'll need to use the stdin command method outlined in the link.

  3. #3
    Join Date
    Aug 2006
    Beans
    428

    Re: at command launches script

    Thanks for your reply - much appreciate it.

    Based on what you've said I think perhaps my problem is with the path.

    Can you tell me where "at" thinks it's at, so to speak. I've tried a whole bunch (although I guess obviously not all!) of paths and none of them has worked.

  4. #4
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: at command launches script

    well, I can't guess where a.sh is. It is your system, your file, not mine.

    If you type ls /path/to/file/a.sh and that is correct, that is the answer you seek.

    15 yrs using linux? Or Windows? Shouldn't matter. The path to a file works the same on both.

  5. #5
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,283
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: at command launches script

    If you type
    Code:
     which a.sh
    it will tell you the full path to it.

  6. #6
    Join Date
    Aug 2006
    Beans
    428

    Re: at command launches script

    Thanks again for dealing with this.

    I realize that you don't know where the file is. But I didn't think that was the issue.

    The situation is:

    I have been "commanding" "at" from the folder that the file is in. And it doesn't work!

    So, I thought, if I knew where "at" is looking for the file - home, bin, usr, wherever - then I could give supply a path to the file. OR move the file to where "at" is looking for it.

    The other thing that I am totally baffled by is that, if I type "sh" in the folder holding the file (sh being required by at apparently), the path to that folder disappears and is replaced by "$". Is this perhaps contributing to the problem and I should being invoking "at" from the $ prompt? Presumably together with the appropriate path.

  7. #7
    Join Date
    Aug 2006
    Beans
    428

    Re: at command launches script

    Thanks for pitching in The Cog - alas you're going to have to hold my hand a bit more.

    From where am I to enter which a.sh?

    Obviously not from the folder containing a.sh. But where?

  8. #8
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,283
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: at command launches script

    So can you name the folder where a.sh is located? I guess you can since you say you have been "commanding" "at" from the folder that the file is in.
    When you say "commanding", does this mean you are openg a terminal (with a command prompt) and typing "a.sh"? That won't work. If the folder that a.ah is located is not in the list of folders where the command prompt will look for commands you type, then it won't find it. You need to type "./a.sh", where the leading "./" means "here in my current working directory". The command prompt will (by default) open and save files in your current working directory, but won't run executable files there, hence needing to specify ./a.sh if you want to execute it.

    Assuming a.sh is located in /home/langstracht/myProject, then the full path to it is /home/langstracht/myProject/a.sh, and this is what you should put in your scripts.

    If this still doesn't help, then please post the full names instead of leaving us guessing and using long descriptions just because we don't know the facts.

  9. #9
    Join Date
    Dec 2014
    Beans
    1,834

    Re: at command launches script

    'which' searches for executables along $PATH. PATH is a variable that holds a colon-separated list of directories. The shell only searches for executables in those directories, so 'which' will tell you which file is actually executed if you enter a command. Note that '.' aka the current working directory is not in PATH for security reasons (imagine unpacking a tar that holds a script named 'ls' and having '.' in the PATH ...). If the directory your script is in is not in $PATH, 'which' will not find it. 'locate' will find it, assuming that the file has existed long enough that the regularly scheduled update of locate's database has been run during the lifetime of the file. You can of course execute any executable file if you give the shell a full path and name for the file, so './executableFile' will execute executableFile in the current working directory and '$HOME/scripts/argelbargel' will work if there's an executable of that unlikely name in a directory named scripts in your HOME.

    So you can call 'which a.sh' in the shell from any directory, but you will only get an answer if 'a.sh' is in a directory in PATH. 'locate a.sh' will find the file even if it isn't in PATH.

    Holger
    Last edited by Holger_Gehrke; July 17th, 2021 at 09:04 PM. Reason: corrected a Germanism

  10. #10
    Join Date
    Aug 2006
    Beans
    428

    Re: at command launches script

    Sorry to all. This has become far more complicated and obtuse than I intended. And I must suppose I have not been clear. For which I apologize.

    But, I thought, to repeat:

    a.sh is in folder Desktop/Scripts

    If I go to that folder and enter bash a.sh (or sh a.sh for that matter!) the script performs just fine.

    Still in that folder, if I then enter an "at" command in ANY of it's forms, it does not work. Presumably because "at" can't find the file.

    So I can move the file to where it can find it. OR somehow find the path that it needs ...

Page 1 of 4 123 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •