LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware - ARM (https://www.linuxquestions.org/questions/slackware-arm-108/)
-   -   Slackware Cronjob (https://www.linuxquestions.org/questions/slackware-arm-108/slackware-cronjob-4175527412/)

captainfreeky 12-05-2014 04:30 AM

Slackware Cronjob
 
I am new to slackware I am trying to execute a cronjob while I have a script but even beeing a root i am not able to add in cronjob I cant edit it.
using current slackware on rasberi pi
( I am yet in learning phase I have been on linux like more then a year but still learning )

louigi600 12-05-2014 07:08 AM

Is dcron installed on your system ?
Is crond running on your system ?
what do you get if you run the following command from root (or as root via sudo):
Code:

crontab -l

frankbell 12-05-2014 08:38 PM

The command for editing your crontab file is

Code:

crontab -e
See man crontab for details.

captainfreeky 12-06-2014 05:13 AM

crontab -l
# If you don't want the output of a cron job mailed to you, you have to direct
# any output to /dev/null. We'll do this here since these jobs should run
# properly on a newly installed system. If a script fails, run-parts will
# mail a notice to root.
#
# Run the hourly, daily, weekly, and monthly cron jobs.
# Jobs that need different timing may be entered into the crontab as before,
# but most really don't need greater granularity than this. If the exact
# times of the hourly, daily, weekly, and monthly cron jobs do not suit your
# needs, feel free to adjust them.
#
# Run hourly cron jobs at 47 minutes after the hour:
47 * * * * /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
#
# Run daily cron jobs at 4:40 every day:
40 4 * * * /usr/bin/run-parts /etc/cron.daily 1> /dev/null
#
# Run weekly cron jobs at 4:30 on the first day of the week:
30 4 * * 0 /usr/bin/run-parts /etc/cron.weekly 1> /dev/null
#
# Run monthly cron jobs at 4:20 on the first day of the month:
20 4 1 * * /usr/bin/run-parts /etc/cron.monthly 1> /dev/null
-----------------------------------------------------------------------------------
while with crontab-e i am not able to write and nither exit via my ssh do not know but i have a script in my user home folder whcih i need to run every 15 min script name eg cleancache.sh
so shall o define below the every day with it absolute path can i have an example finding a little tuff as i am from debain and yet learning

louigi600 12-07-2014 04:58 AM

While "crontab -l" just dumps the user's crontab (I asked you to do it from root because I know Slackware has some default cron jobs for root) "crontab -e" opens up an editor to modify the crontab.

The editor that will be used to edit the crontab may depend on your user environment (EDITOR or VISUAL environment variables). If they are not set at all or if either one is set to vi then vi will be used to edit your crontab.

Now if you want to run every 15 minutes a script in a user directory, and supposing the script may be run from the user itself without having to use sudo and that the script is in /home/captainfreeky/cleancache.sh , you might want to add something like this in your user's crontab


Code:

*/15 * * * * [ -x /home/captainfreeky/cleancache.sh ] && /home/captainfreeky/cleancache.sh >/dev/null 2>&1
Once you have added that save the file just like you would with any other file you edited and just wait for cron to pick up your scheduled job.

If you don't know how to use whatever editor is being used fro editin yout crontab run something like this:
Code:

echo "$(crontab -l)
*/15 * * * * [ -x /home/captainfreeky/cleancache.sh ] && /home/captainfreeky/cleancache.sh >/dev/null 2>&1" | crontab -

That should append what you want to your user's crontab ... if it happens to be empty it can be simplified like this:
Code:

echo "*/15 * * * * [ -x /home/captainfreeky/cleancache.sh ] && /home/captainfreeky/cleancache.sh >/dev/null 2>&1" | crontab -

captainfreeky 12-09-2014 01:02 PM

Quote:

Originally Posted by louigi600 (Post 5280789)
While "crontab -l" just dumps the user's crontab (I asked you to do it from root because I know Slackware has some default cron jobs for root) "crontab -e" opens up an editor to modify the crontab.

The editor that will be used to edit the crontab may depend on your user environment (EDITOR or VISUAL environment variables). If they are not set at all or if either one is set to vi then vi will be used to edit your crontab.

Now if you want to run every 15 minutes a script in a user directory, and supposing the script may be run from the user itself without having to use sudo and that the script is in /home/captainfreeky/cleancache.sh , you might want to add something like this in your user's crontab


Code:

*/15 * * * * [ -x /home/captainfreeky/cleancache.sh ] && /home/captainfreeky/cleancache.sh >/dev/null 2>&1
Once you have added that save the file just like you would with any other file you edited and just wait for cron to pick up your scheduled job.

If you don't know how to use whatever editor is being used fro editin yout crontab run something like this:
Code:

echo "$(crontab -l)
*/15 * * * * [ -x /home/captainfreeky/cleancache.sh ] && /home/captainfreeky/cleancache.sh >/dev/null 2>&1" | crontab -

That should append what you want to your user's crontab ... if it happens to be empty it can be simplified like this:
Code:

echo "*/15 * * * * [ -x /home/captainfreeky/cleancache.sh ] && /home/captainfreeky/cleancache.sh >/dev/null 2>&1" | crontab -

Now i know why i was not able to edit because of vim how can i change default to nanao and other part what is /dev/null 2>&1" | crontab - indicate orif not can you give me a link where can be explained clearly sorry as i am learning wanted to clear the doubt

frankbell 12-09-2014 07:48 PM

The third post in this LQ thread provides one solution. Use this command to edit crontab:

Code:

env EDITOR=nano crontab -e
I just tested it and it works in Slackware. There are also several suggestions as to ways to change the default editor, which I did not test.

The code

Code:

>/dev/null 2>&1
redirects errors to /dev/null, that is, the bit bucket. http://www.xaprb.com/blog/2006/06/06...vnull-21-mean/

louigi600 12-10-2014 02:13 AM

"crontab -" receives input from stdin and put it in your crontab.

">/dev/null 2>&1" redirects stdout to /dev/null and appends standard error to stdout.

So
Code:

echo "*/15 * * * * [ -x /home/captainfreeky/cleancache.sh ] && /home/captainfreeky/cleancache.sh >/dev/null 2>&1" | crontab -
puts your script into your crontab, overwriting whatever pas previously in there, and trashing any output the script makes.


All times are GMT -5. The time now is 01:47 AM.