LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware > Slackware - ARM
User Name
Password
Slackware - ARM This forum is for the discussion of Slackware ARM.

Notices


Reply
  Search this Thread
Old 12-05-2014, 04:30 AM   #1
captainfreeky
LQ Newbie
 
Registered: Jun 2014
Distribution: Slackware 14.1 FreeBSD10.2
Posts: 15

Rep: Reputation: 2
Question 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 )

Last edited by captainfreeky; 12-05-2014 at 05:12 AM.
 
Old 12-05-2014, 07:08 AM   #2
louigi600
Member
 
Registered: Dec 2013
Location: Italy
Distribution: Slackware
Posts: 634
Blog Entries: 20

Rep: Reputation: 81
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
 
Old 12-05-2014, 08:38 PM   #3
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,257
Blog Entries: 28

Rep: Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119
The command for editing your crontab file is

Code:
crontab -e
See man crontab for details.
 
Old 12-06-2014, 05:13 AM   #4
captainfreeky
LQ Newbie
 
Registered: Jun 2014
Distribution: Slackware 14.1 FreeBSD10.2
Posts: 15

Original Poster
Rep: Reputation: 2
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
 
Old 12-07-2014, 04:58 AM   #5
louigi600
Member
 
Registered: Dec 2013
Location: Italy
Distribution: Slackware
Posts: 634
Blog Entries: 20

Rep: Reputation: 81
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 -
 
1 members found this post helpful.
Old 12-09-2014, 01:02 PM   #6
captainfreeky
LQ Newbie
 
Registered: Jun 2014
Distribution: Slackware 14.1 FreeBSD10.2
Posts: 15

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by louigi600 View Post
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
 
Old 12-09-2014, 07:48 PM   #7
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,257
Blog Entries: 28

Rep: Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119Reputation: 6119
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/
 
Old 12-10-2014, 02:13 AM   #8
louigi600
Member
 
Registered: Dec 2013
Location: Italy
Distribution: Slackware
Posts: 634
Blog Entries: 20

Rep: Reputation: 81
"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.

Last edited by louigi600; 12-10-2014 at 03:51 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cronjob shaik_rafi2009 Linux - Newbie 8 01-07-2013 08:44 AM
Slackware external drive cronjob help Daedra Slackware 10 10-25-2011 07:57 PM
Cronjob..... milindpk Linux - Newbie 6 05-06-2010 06:52 PM
cronjob ugob Linux - Software 0 03-03-2004 09:20 AM
Su in a cronjob michedlp Programming 3 11-06-2003 08:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware > Slackware - ARM

All times are GMT -5. The time now is 12:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration