At script, Possible?


Results 1 to 13 of 13

Thread: At script, Possible?

  1. #1
    Join Date
    May 2003
    Location
    Kuala Lumpur, Malaysia
    Posts
    53

    Solved - At script, Possible??

    Hello there

    Can I write a script to schedule an at job
    I tried (a segment of the script files only)

    at 13:00
    /home/hk/scripts/abc.sh
    ^d
    it just doesn't work
    abc.sh is the script that i want to run at 13:00 today

    Thanks in advance
    Last edited by hauwkim; 04-12-2005 at 02:48 AM.

  2. #2
    Join Date
    Dec 2000
    Location
    Glasgow, Scotland
    Posts
    4,361
    You could add it to your crontab instead - might be easier.

    Just add a line something like this:

    Code:
    0 13 * * * hk /home/hk/scripts/abc.sh
    mrBen "Carpe Aptenodytes"

    Linux User #216794

    My blog page

    3rd year running - get yourself to LugRadio Live 7th-8th July 2007, Wolverhampton, UK. The premier FLOSS community event.

  3. #3
    Join Date
    May 2003
    Location
    Kuala Lumpur, Malaysia
    Posts
    53
    Hello mrBen

    I did.
    I've also output the results into a dump file.
    It looks as thou the script started to run then it jus exited or hangs whithout returning any errors...

    I run the same script as an at job, it was completed sucessfully

    Thats how I came to the conclusion of using the cron to schedule the at jobs.

    But so far the at script did not work. Even if I execute it manually.


  4. #4
    Join Date
    Dec 2000
    Location
    Glasgow, Scotland
    Posts
    4,361
    Originally posted by hauwkim
    Hello mrBen

    I did.
    I've also output the results into a dump file.
    It looks as thou the script started to run then it jus exited or hangs whithout returning any errors...

    I run the same script as an at job, it was completed sucessfully

    Thats how I came to the conclusion of using the cron to schedule the at jobs.

    But so far the at script did not work. Even if I execute it manually.

    What - you're using an at script within a cron job? Why?

    Double check your permissions - that's usually a key for cron jobs, IIRC.

    And if you're using at, then I don't think you need the colon - 1300 should do. Plus, if you are running from a terminal window, you will probably need to leave the window open so that it continues to process the at command.

    Oh - and check that the job is accepted by running at -l (that's an L, not a 1) to list the current at jobs.
    mrBen "Carpe Aptenodytes"

    Linux User #216794

    My blog page

    3rd year running - get yourself to LugRadio Live 7th-8th July 2007, Wolverhampton, UK. The premier FLOSS community event.

  5. #5
    Join Date
    May 2003
    Location
    Kuala Lumpur, Malaysia
    Posts
    53
    okie i will do more digging in cron

    for the mean time can i write a script to call the cron job?
    somethin like
    Code:
    at 1300
    ls
    ^D
    if I run the script above what it will do is it will list out all the folders in the current directory?

  6. #6
    Join Date
    Dec 2000
    Location
    Glasgow, Scotland
    Posts
    4,361
    Originally posted by hauwkim
    okie i will do more digging in cron

    for the mean time can i write a script to call the cron job?
    You don't write a script to call a cron job. Cron is for scheduling - when you add a line to your crontab file, it tells it to run a script at a particular time, and then the cron daemon will do it for you.


    somethin like
    Code:
    at 1300
    ls
    ^D
    if I run the script above what it will do is it will list out all the folders in the current directory?
    Kind of, yes. But it won't do it in the current terminal, thus you won't see anything. Pipe the output to a file, and then open that file.

    Code:
    mrben@hobbes:~$ touch at-test
    mrben@hobbes:~$ cat at-test
    mrben@hobbes:~$ date
    Mon Apr 11 10:33:07 BST 2005
    mrben@hobbes:~$ at 1034
    warning: commands will be executed using /bin/sh
    at> echo "this is a test" > at-test
    at> <EOT>
    job 2 at 2005-04-11 10:34
    mrben@hobbes:~$ at -l
    2       2005-04-11 10:34 a mrben
    mrben@hobbes:~$ cat at-test
    this is a test
    mrben@hobbes:~$ at -l
    mrben@hobbes:~$
    mrBen "Carpe Aptenodytes"

    Linux User #216794

    My blog page

    3rd year running - get yourself to LugRadio Live 7th-8th July 2007, Wolverhampton, UK. The premier FLOSS community event.

  7. #7
    Join Date
    May 2003
    Location
    Kuala Lumpur, Malaysia
    Posts
    53
    one last thing

    if i wrote

    Code:
    #!/bin/bash
    at 1034
    echo "this is a test" > at-test
    ^D
    and save the above as test.sh

    then if i excute ./test.sh
    and then later do a at -l, i should be able to see something like
    2 2005-04-11 10:34 a
    and it will create a file call "at-test" with the content "this is a test"

    but after i excute the test.sh it went into the at prompt (at>)

    does this mean this cannot be done this way or i have written a wrong test.sh

    Many thanks

  8. #8
    Join Date
    Dec 2000
    Location
    Glasgow, Scotland
    Posts
    4,361
    OK - you need to think about how bash executes scripts: it does them line by line as if you were typing them in. When your script gets to at 1034 bash runs the at command and then waits for standard input. The script doesn't replace standard input.

    If you use at -f then it can use a file as an input instead of standard input, which would then work within a script

    but

    this is getting very awkward very quickly - can you explain why you are not just using a script within cron, rather than trying to put at within a script? Are your jobs not regular?
    mrBen "Carpe Aptenodytes"

    Linux User #216794

    My blog page

    3rd year running - get yourself to LugRadio Live 7th-8th July 2007, Wolverhampton, UK. The premier FLOSS community event.

  9. #9
    Join Date
    Apr 2003
    Location
    UK
    Posts
    1,180
    To do what you want and give at the input it wants try
    Code:
    echo 'echo "this is a test" > at-test'|at 1034
    it works for me.

    I worked this out because I use at to play music as an alarm clock and the request for input was annoying.

  10. #10
    Join Date
    May 2003
    Location
    Kuala Lumpur, Malaysia
    Posts
    53
    this is getting very awkward very quickly - can you explain why you are not just using a script within cron, rather than trying to put at within a script? Are your jobs not regular?
    The main reason why I came to this work around is because the script file that I have run runs smoothly when I use "at" but it does not complete if I schedule a cron job.

    I have done a bit of digging, what I have understand is that cron does not execute batch jobs in full session mode. In order for it to finish the job I will need to provide all the runtime environment needed by the batch either in the .profile or the batch file itself.

    You might wonder what does the batch file is actually doing. Well ... what it does is it will dump DB2 data into the Linux box. After translation it will the dump the same data into ORA.

    The funny thing is that this batch file has been running fine untill recently.

    One more thing, if I would to use "at -l" how do I do a "ctr+d" in the input file? I will normally do a ctr+d to submit the at job if I wolud to do this manually. I have try "^D" and "^d" it just did not work

    And retsaw, I will try that when I got back inda off tomorrow. I have tried it on my house pc and it works.
    Last edited by hauwkim; 04-11-2005 at 12:15 PM.

  11. #11
    Join Date
    Nov 2002
    Location
    Stockholm/Sweden
    Posts
    106
    Perhaps your script is depending on some environment variables not found in the shell which cron is executed with (usually bourne shell)?
    Have a look at crontab(5) and see if this could be solved by using the SHELL or PATH variable.

    You could also redirect any output from your script to a file, to see if any clues are given to what is wrong.
    ::.. Debian GNU/Linux für alle ..::
    Home | MAME Arcade | Screenshots

  12. #12
    Join Date
    Sep 2002
    Location
    Valencia, California
    Posts
    436

    My script

    Here's a snippet of my script that I use to remove my customers' data after a month:

    echo rm -Rf \""/home/incoming/customer/$*"\" | at + 1 month

  13. #13
    Join Date
    May 2003
    Location
    Kuala Lumpur, Malaysia
    Posts
    53

    [SOLVE]

    tat did it

    Code:
    echo 'echo "this is a test" > at-test'|at 1034
    thanks guys for all of your effort

    thanks again

Posting Permissions

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