Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I have written a code which moves .trc files from source directive to backup directive. Now I have taken time (how much time older), source path and backup path as command line arguments for this file. Now when I invoke the script from sh, it works fine. But in crontab it is not working, which left me wondering if crontab allows passing command line arguments or not. My sh command is :
sh trace_bkp.sh 2 /home/adhikarisubir/test/basic_unix /home/adhikarisubir/test_bkp
where 2 defines 2 minutes older files, next one is soruce path and the last one is target path. I set the same in crontab as:
*/5 * * * * sh /home/adhikarisubir/test/basic_unix/trace_bkp.sh 2 /home/adhikarisubir/test/basic_unix /home/adhikarisubir/test_bkp
Yes, crotab lines can get arguments as the man page says so.
Most likely something goes wrong while calling that command that resides in the change of environment from your console to the not-a-console cron environment.
Usually its best to add logging functions to your cron line to get the output of whats happening.
*/5 * * * * sh /home/adhikarisubir/test/basic_unix/trace_bkp.sh 2 /home/adhikarisubir/test/basic_unix /home/adhikarisubir/test_bkp >> /home/adhikarisubir/test/basic_unix/cron.log 2>&1
Then read that log and you will see how it goes wrong.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I am looking to execute a alias on my terminal which will login to another shell and execute a command there.
For example,
sh = 'ssh admin#x.x.x.x'
shls = 'sh;ls' (also tried 'sh && ls')
In this scenario, when i give 'shls', i want to ssh to (pwd less entry enabled) x.x.x.x and then execute ls command over there. But the 'ls' part is not working.
I understand the shell changed and hence its no longer in parent shell's scope to trigger the ls, but just wondering if there is a way to push it to the logged in shell and execute there.
Infact, i wanted to use another alias which is avaiable in x.x.x.x in place of 'ls' but as a first step i want to atleast get this working.
Hope i could put it clearly, Thanks in advance for your help.
You can pass a command to ssh as an argument (after the various connection parameters):
alias shls='ssh admin#x.x.x.x ls'
BTW, I'd recommend against aliasing sh -- that's a commonly used command to run a shell script(*), and giving it a different meaning could cause confusion.
(* Though instead using the sh command, it's generally better to give the script a proper shebang line, and just enter its path.)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I need to quickly and temporarily disable a particular job in crontab under linux. How can I do that?
The quickest way would be to edit the crontab file (which can be done by typing crontab -e) and simply comment the job you want disabled. Comment lines in crontab start with a #.
0 0 1 * * this_job_i_want.sh
# uncomment below to enable
# 0 0 2 * * this_job_i_dont_want.sh
Simply edit your cron time to run every February 30. ;)
* * 30 2 * this_job_will_never_run.sh
This is especially helpful for those using a GUI to manage their cronjobs (i.e. cPanel, Plesk, etc.) and don't have access to the actual cron file.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I would like a cronjob that runs every 5min with the condition that it doesn't start at time 0.
Current schedule is:
*/5 * * * *
However, this will kick off the script at 00:00. I need something like (5-60)/5 * * * *
Thanks!
I'm not sure there is a way to do this in cron. You might be better off leaving the schedule as is, and checking the time in the beginning of your script, and using a condition to exit the script if it is not supposed to run at that time.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have a text file containing a specific date and time.
I want to be able to run a script at the time specified in that file.
How would you achieve that?
Create another script that runs in background (sort of a deamon) and checks every second if the current time is matching the time in the file?
Is there another way?
The machine is a linux server , Debian wheezy.
Thanks in advance
Look at the following:
echo "ls -l" | at 07:00
This code line executes "ls -l" at a specific time. This is an example of executing something (a command in my example) at a specific time. "at" is the command you were really looking for. You can read the specifications here:
http://manpages.ubuntu.com/manpages/precise/en/man1/at.1posix.html
http://manpages.ubuntu.com/manpages/xenial/man1/at.1posix.html
The at command exists specifically for this purpose (unlike cron which is intended for scheduling recurring tasks).
at $(cat file) </path/to/script
Cron is good for something that will run periodically, like every Saturday at 4am. There's also anacron, which works around power shutdowns, sleeps, and whatnot. As well as at.
But for a one-off solution, that doesn't require root or anything, you can just use date to compute the seconds-since-epoch of the target time as well as the present time, then use expr to find the difference, and sleep that many seconds.
Usually in Linux you use crontab for this kind of scduled tasks. But you have to specify the time when you "setup the timer" - so if you want it to be configurable in the file itself, you will have to create some mechanism to do that.
But in general, you would use for example:
30 1 * * 5 /path/to/script/script.sh
Would execute the script every Friday at 1:30 (AM)
Here:
30 is minutes
1 is hour
next 2 *'s are day of month and month (in that order) and 5 is weekday
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I need to install some cron jobs with my Ubuntu installation package. The ones that run every day or hour are easy: I can just create a symlink from /etc/cron.daily to my script.
However, I also have a script that I would like to run every 10 minutes. There is no such thing as /etc/cron.minutely. Also I am not sure how to edit crontab without using the interactive editor (crontab -e). What is the best way to go about this?
Your package can simply put a file in /etc/cron.d/
The text file should contain something like this, to run a command every 10 minutes:
*/10 * * * * root /path/to/command
Google 'cron format' for more info, and yes, this belongs in askubuntu or superuser.
You need to add the username (root) to the line, as shown above. Apparently this is necessary for files in cron.d, but I can't find a definitive document.**
cron should pick this new job up automatically.