LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-08-2006, 11:58 AM   #1
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Rep: Reputation: 85
Question help improve my script that updates the system by cron


What do people think of my script? Cron runs it daily. I know it needs improvements and error checking, so give me your ideas. Thanks. I know people dont like the automation -y part, so what could go wrong? I want the automation. Lets say apt complained of a dependency problem. Then my script should do something else in that case, or maybe it won't do anything because I did not include --force-yes.

Code:
#!/bin/bash
if [ `whoami` != "root" ]; then
   echo "You must be root to execute this script."
   exit
fi
apt-get update
apt-get upgrade -y
echo "----------------------------------------------" >> /tmp/mylog
echo "Apt successfully updated the system:" >> /tmp/mylog
echo $(date) >> /tmp/mylog
echo >> /tmp/mylog
apt-history show >> /tmp/mylog
echo >> /tmp/mylog
cat /tmp/mylog | sendEmail -t myemail@gmail.com -f root@mydomain.org -u "Apt successful system update" -q
cat /tmp/mylog | tee -a /var/log/pkgsbyapt
rm -f /tmp/mylog
apt-get clean
exit 0

Last edited by fakie_flip; 10-08-2006 at 11:59 AM.
 
Old 10-08-2006, 12:12 PM   #2
pete1234
Member
 
Registered: May 2005
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172

Rep: Reputation: 30
Not sure if it's an improvement, but I always check user ID like this:

Code:
if [ $UID -ne 0 ]; then
   echo "You must be root to execute this script."
   exit
fi
 
  


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
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
Improve system perfomance? tidiman07 Ubuntu 35 07-28-2006 10:33 AM
How to improve my mysql backup cron job stardotstar Programming 8 05-25-2006 06:11 AM
I need help to improve a little script... informix Linux - Software 0 07-19-2004 07:55 PM
CRON and DNS updates thenebula Linux - Newbie 1 10-13-2003 05:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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