LinuxQuestions.org
Register a domain and help support LQ
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 08-10-2006, 04:52 PM   #1
mwade
Member
 
Registered: Aug 2006
Distribution: Ubuntu 8.10
Posts: 43

Rep: Reputation: 15
Cron scripting to automatically update smart


Hi all. I am new to linux but like nearly everything about it! I use Suse 10.1 and I'm having loads of fun learning. I'm giving scripting a go at the minute and I believe with the know how you can produce some extremely useful scripts. Now to the point, I am trying to update smart package manager, then smart upgrade, then smart check, then smart fix all on a schedule. I did some hunting and found that cron does the scheduling, had a go at that and seemed to get the hang of it a bit. A couple of problems though...

1. It mails the output to root mail
2. I don't know how to answer yes when it asks me if i want to upgrade packages

How do I get it to show the output in a different way, i.e console or even a log file instead of mail cuz all the header and stuff is annoying. Also how do I return a value to the script?

Thanks for your replies.
 
Old 08-10-2006, 08:04 PM   #2
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
Never used smart so I'm not sure what input it wants. If it only asks for a simple Y/n then yes should be able to handle it otherwise check out expect. Cron sends all stdout (standard output) to sendmail which is what generates the email, you can use boring old output redirection to forward it somewhere else ie. a log file. Append something like this to the end of the command:
Code:
> /var/log/smart/$(date +%Y%m%d)-upgrade.log 2>&1
# that will create eg. /var/log/smart/20060811-upgrade.log. if it were me i'd seperate days like that so any issues will be easy to track down
Hope that helped
 
Old 08-11-2006, 08:19 AM   #3
mwade
Member
 
Registered: Aug 2006
Distribution: Ubuntu 8.10
Posts: 43

Original Poster
Rep: Reputation: 15
Smart is an idiots way of using linux which is why it suits me There are 4 commands that I use...

Smart Update (updates smart software without requiring feedback)
Smart Upgrade (checks what needs to be changed then asks y/n ONCE if you want to change them)
Smart Check (checks for dependency errors without requiring feedback)
Smart Fix (fixes errors asking y/n ONCE if you want to fix them)

Simple enough I'll have a look what I can do with that piece of code later when I get in. It looks like its what I want though. Thanks for your reply
 
Old 08-11-2006, 10:47 AM   #4
mwade
Member
 
Registered: Aug 2006
Distribution: Ubuntu 8.10
Posts: 43

Original Poster
Rep: Reputation: 15
Hi again, I've tried this and it doesn't seem to work...

* * * * * smart update /var/log/smart/$(date +%Y%m%d)-upgrade.log 2>&1

thats what I added to the first line of the crontab. I believe it does a smart update every minute of every hour of every day of every month of every year and records the output in the log file but the console just told me "You have new mail in /var/spool/mail/root" and the mail said...


Subject: Cron <root@linux-odf8> smart update /var/log/smart/$(date +
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>

/bin/sh: -c: line 0: unexpected EOF while looking for matching `)'
/bin/sh: -c: line 1: syntax error: unexpected end of file

...with the header stripped out. Does anyone have any idea what this means?
 
Old 08-11-2006, 06:59 PM   #5
mwade
Member
 
Registered: Aug 2006
Distribution: Ubuntu 8.10
Posts: 43

Original Poster
Rep: Reputation: 15
Hi again, I've done a bit of research into the matter and found this is how to approach the problem...

* * * * * smart update >> /usr/local/logs/mylog.log

Now for some reason this doesn't...

* * * * * smart update >> /usr/local/logs/$(date +%Y%m%d)-upgrade.log 2>&1

It doesn't seem to like the whole save the file as the current date format. Any ideas how to fix this, looking round on the web this looks fine but it still doesn't work. I'm getting this error in my root mail...

/bin/sh: -c: line 0: unexpected EOF while looking for matching `)'
/bin/sh: -c: line 1: syntax error: unexpected end of file

Any help is appreciated.
 
Old 08-11-2006, 09:38 PM   #6
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
I've got to admit I've never really played with cron so I'm not 100% sure how it parsed the crontab, I'm just assuming I can use sh in there which I don't know if you can.

Firstly, using '>>' will append, if you're creating a new log for each update you should use '>' which is what I put in the first place Try a difference syntax and see if it works...
Code:
* * * * * smart update >> /usr/local/logs/`date +%Y%m%d`-upgrade.log 2>&1
 
Old 08-12-2006, 08:00 AM   #7
mwade
Member
 
Registered: Aug 2006
Distribution: Ubuntu 8.10
Posts: 43

Original Poster
Rep: Reputation: 15
I've worked out what's happened, I'll post here for googlers.

crontab will not accept the date format in the output. What I did to get round this is wrote a script named "3" containing...

#!/bin/bash
smart update > /usr/local/logs/`date +%Y%m%d%k`.log 2>&1

This updates smart and then sends the output to a log file created by the date format which will be YearMonthDayHour. Then in the crontab I put....

0 * * * * /usr/local/bin/3

Which means every hour it calls the script "3" which I saved in /usr/local/bin

This works fine and will display the output of smart update in the log file. Now all I have to do is work out how to send input to the script when I do smart upgrade.
 
Old 08-12-2006, 09:53 PM   #8
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
Good to hear!
Quote:
Now all I have to do is work out how to send input to the script when I do smart upgrade.
man expect
man yes

 
  


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
error messages when i try to update with smart dasy2k1 Suse/Novell 4 08-12-2006 03:57 PM
SuSE 10.0 security Update with 'smart' ? grumpf Suse/Novell 2 07-08-2006 11:31 AM
CRON Process Won't Execute Automatically Transition Linux - General 5 01-14-2005 03:51 PM
Cron Scripting Weirdness . . . Deeter Linux - General 7 07-28-2003 07:02 PM
How do you control if a service (cron for example) is started automatically? Rimmer Linux - General 2 05-16-2001 11:51 AM


All times are GMT -5. The time now is 06:59 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration