LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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-05-2016, 04:23 AM   #46
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553

Quote:
Originally Posted by QuestionMqrk View Post
Here's the end result of the shebang;

Code:
>0 11 * * * /usr/sbin/smartctl -aixcA -d sat /dev/sda > /home/michaelzheludev/CRON/smartctl-output-$(/bin/date +\%d\%m\%y)
in case someone needs to do something similar in the future.
Glad you got sorted.

You'll find that many admins (myself included) would have used a script rather than modify the cron job, so you'd end up with:

/root/getsmart.sh
Code:
#!/bin/bash

# Author : TenTenths
# Purpose: Dump drive smartctl data to log file
# Version: 1.0
# Date   : 5th Oct 2016

# Version History
# 1.0 Initial version

# Set your options and log file as appropriate
LOGFILE="/home/michaelzheludev/CRON/smartctl-output-$(/bin/date +%d%m%y)"
OPTIONS="-aixcA -d sat /dev/sda"

# Script logic starts here
/usr/sbin/smartctl ${OPTIONS} >> ${LOGFILE}

# Elvis Has Left The Server
Then your cron can just be:

Code:
00 11 * * * /root/getsmart.sh
 
Old 10-05-2016, 07:57 AM   #47
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by Turbocapitalist View Post
... Also, if you are planning on accumulating a lot of logs, you might switch to %y%m%d instead so it sorts better. That's also known as %F, see the manual page for "date" for the details.
+1, i also like:
Code:
date +%Y-%j
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:53 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