LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-04-2016, 07:22 AM   #16
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 1,618
Blog Entries: 3

Rep: Reputation: 692Reputation: 692Reputation: 692Reputation: 692Reputation: 692Reputation: 692

Quote:
Originally Posted by TenTenths View Post
Jeez, another one I missed! Good catch TC!
"Given enough eyeballs, all bugs are shallow."
 
1 members found this post helpful.
Old 10-04-2016, 07:29 AM   #17
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 3,329

Rep: Reputation: 575Reputation: 575Reputation: 575Reputation: 575Reputation: 575Reputation: 575
if you have not figured it out yet this is what I do. mine only runs once a week.

Code:
userx@voided.org & ~ >> $cat /etc/cron.weekly/trim
#!/bin/sh
LOG=/var/log/trim.log
echo "*** $(date -R) (root)***" >> $LOG
fstrim -v / >> $LOG
echo "*** $(date -R)-(data) ***" >> $LOG
fstrim -v /media/data >> $LOG
bash script file chmod +x youorFileName then it stores a log in /var/log dated

then I linked my dcron (app) to my services so it starts the service every time I boot up

so yeah it going to be need to be put in your /etc/cron.(put it in whichever directroy you need to have it run)

Code:
userx@voided.org & ~ >> $ls  /etc/cron.*
/etc/cron.d:

/etc/cron.daily:
makewhatis  shadow  updatedb

/etc/cron.hourly:

/etc/cron.monthly:

/etc/cron.weekly:
trim

/etc/cron.yearly:
the other way too works assiging it to a job

Last edited by BW-userx; 10-04-2016 at 07:33 AM.
 
Old 10-04-2016, 07:33 AM   #18
QuestionMqrk
LQ Newbie
 
Registered: Oct 2016
Posts: 29

Original Poster
Rep: Reputation: Disabled
I feel pretty stupid that I can't get this to work.

Here's the directory I need it in;

/home/XXXXXXXXXXXXXXX/CRON

And here's the command I entered into
>sudo smartctl -e EDIT: sudo crontab -e

29 14 * * * /usr/sbin/smartctl -aixcA -d sat /dev/sda > /home/XXXXXXXXXXXXXXX/CRON/smartctl-output-$(date +%d%m%y_%H%M)


PS: The X's is censoring my full name, which is in the directory.

Please someone tell me i'm not crazy and there's another mistake somewhere.

Last edited by QuestionMqrk; 10-04-2016 at 07:38 AM.
 
Old 10-04-2016, 07:36 AM   #19
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,336

Rep: Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824
Quote:
Originally Posted by QuestionMqrk View Post
And here's the command I entered into
>sudo smartctl -e
You need to use:
Code:
 sudo crontab -e
to edit the cron
 
Old 10-04-2016, 07:38 AM   #20
QuestionMqrk
LQ Newbie
 
Registered: Oct 2016
Posts: 29

Original Poster
Rep: Reputation: Disabled
Ah yes, that's what I meant; edited.
 
Old 10-04-2016, 07:38 AM   #21
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 3,329

Rep: Reputation: 575Reputation: 575Reputation: 575Reputation: 575Reputation: 575Reputation: 575
Your cron job looks as follows for system jobs:

1 2 3 4 5 USERNAME /path/to/command arg1 arg2

OR

1 2 3 4 5 USERNAME /path/to/script.sh

Jobs but not Jobs has in apple
 
Old 10-04-2016, 07:39 AM   #22
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 1,618
Blog Entries: 3

Rep: Reputation: 692Reputation: 692Reputation: 692Reputation: 692Reputation: 692Reputation: 692
Ok. Maybe you mean sudo crontab -e? That will put the job in the root's crontab, but it will be able to write anywhere.

One quirk that we've forgotten to mention is that you need an empty line at the bottom of your crontab. Please check that you have an empty line there. (Dunno why, but it's necessary.)
 
Old 10-04-2016, 07:44 AM   #23
QuestionMqrk
LQ Newbie
 
Registered: Oct 2016
Posts: 29

Original Poster
Rep: Reputation: Disabled
I didn't leave a space between the notes and the command, so I was sure that was it. Imagine my expression when the time passed and nothing happened. :S

Is it correct to; if I want it to happen every day at 14:45, type "45 14 * * *" as I have been doing?

EDIT

I just realised I missread the note about the empty line; but I have one below the command and it still doesn't work.

Last edited by QuestionMqrk; 10-04-2016 at 07:49 AM.
 
Old 10-04-2016, 08:08 AM   #24
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,062

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
please post the contents of
Code:
sudo crontab -l
in code tags.
 
Old 10-04-2016, 08:12 AM   #25
QuestionMqrk
LQ Newbie
 
Registered: Oct 2016
Posts: 29

Original Poster
Rep: Reputation: Disabled
Code:
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
50 14 * * * /usr/sbin/smartctl -aixcA -d sat /dev/sda > /home/michaelzheludev/CRON/smartctl-output-$(date +%d%m%y_%H%M)
 
Old 10-04-2016, 08:13 AM   #26
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 1,618
Blog Entries: 3

Rep: Reputation: 692Reputation: 692Reputation: 692Reputation: 692Reputation: 692Reputation: 692
Sometimes things work better as script.

First make the script:

Code:
touch ./check_drive_status

chmod +x ./check_drive_status

cat <<EOS > ./check_drive_status
#!/bin/sh

/usr/sbin/smartctl -aixcA -d sat /dev/sda > /home/XXXX/smartctl-output-$(date +%d%m%y_%H%M)
EOS
Then make sure it works:

Code:
sudo ./check_drive_status
Then copy the script.

Code:
sudo cp ./check_drive_status /usr/local/sbin/.
Then put /usr/local/sbin/check_drive_status in your crontab instead of what you have.
 
Old 10-04-2016, 08:17 AM   #27
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,062

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Quote:
Originally Posted by QuestionMqrk View Post
Code:
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
50 14 * * * /usr/sbin/smartctl -aixcA -d sat /dev/sda > /home/michaelzheludev/CRON/smartctl-output-$(date +%d%m%y_%H%M)
does the command work in the command-line (without using cron) ?
try putting an echo before the command in cron as a test.
what timezone are you in (this is scheduled to run at 2:50 pm everyday) ?
 
Old 10-04-2016, 08:23 AM   #28
QuestionMqrk
LQ Newbie
 
Registered: Oct 2016
Posts: 29

Original Poster
Rep: Reputation: Disabled
When I take out the date and run the command without Cron it works.
 
Old 10-04-2016, 08:24 AM   #29
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,336

Rep: Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824
Ah, another one we all missed, you'll need /the/full/path/to/date (same as was done for smartctl) for the date bit to work
 
2 members found this post helpful.
Old 10-04-2016, 08:25 AM   #30
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,062

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
^ try it with the date ?
 
  


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
Is a Cron or Script trouble? benygr Linux - Newbie 7 07-05-2013 01:38 PM
Having trouble setting an environment variable with a cron job PaulB0 Linux - Newbie 5 06-23-2012 02:06 AM
Trouble with cron nonik Linux - General 4 02-08-2008 04:54 PM
Trouble with cron GavB Linux - Newbie 1 11-09-2006 01:39 PM
need help with setting up a cron juancha Linux - Newbie 2 11-07-2006 07:28 PM


All times are GMT -5. The time now is 10:45 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration