Register
It is currently Thu Nov 27, 2014 8:53 pm

A very simple script needed.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Wed Mar 02, 2011 5:17 pm   

Joined: Wed Mar 02, 2011 5:16 pm
Posts: 1
All I want to do is download a "homepage", and then .zip it and email it. Help is much appreciated!


Top
 Profile  
 PostPosted: Thu Mar 03, 2011 7:00 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Hi Arguile, welcome to the forum!

This request sounds simple enough. What have you tried so far?

Thanks!
-Jeo


Top
 Profile YIM  
 PostPosted: Thu Mar 03, 2011 9:01 pm   

Joined: Mon May 31, 2010 7:40 pm
Posts: 25
I am one of those people who hates doing someone else's work. However, hence I am learning bash and need as much practice as I can get I can atleast post some of the initial code which I think can be helpful.

I would also appreciate others to chime in and let me know how I can better my script snippets.

Code:
#!/bin/bash

HOME=/home/user/scripts/bash/html
LOGFILE=$HOME/wget.log
DATE=`date +%Y-%m-%d`

wget http://www.somesite.net/index.html

zip-file () {
    for i in $HOME/index.html; do
      zip -j backup_`date +%Y-%m-%d`.zip $i
done
}

if [ -f $HOME/index.html ]; then
    zip-file;
    echo -n $DATE: file here... > $LOGFILE
else
    echo -n $DATE: no file here... > $LOGFILE
exit 1
fi


Ok so now I need help. I've added to the script snippet above and wanted to use the elif clause, however, I am tired and need a hand. Here is what I have thus far.

Please someone chime in

Code:
#!/bin/bash

HOME=/home/user/scripts/bash/html
TMP=$HOME/tmp
LOGFILE=$HOME/wget.log
DATE=`date +%Y-%m-%d`
WGET="wget -P $TMP http://www.somesite.net/index.html"

zip-file () {
    for i in $TMP/index.html; do
      zip -mj $TMP/backup_`date +%Y-%m-%d`.zip $i
done
}

if [ ! -d $TMP ]; then
    mkdir $TMP
fi

if [ ! -f $TMP/index.html ]; then
    $WGET
fi

if [ -f $TMP/index.html ]; then
    zip-file;
        echo -n $DATE: file here... >> $LOGFILE
else
    echo -n $DATE: no file here... >> $LOGFILE
exit 1
fi


Top
 Profile  
 PostPosted: Fri Mar 04, 2011 7:49 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Looks good canit0!

That script looks good! I don't think I understand the question though. For what purpose did you wish to use the elif?

Thanks!
-Jeo


Top
 Profile YIM  
 PostPosted: Sat Mar 05, 2011 6:54 pm   

Joined: Mon May 31, 2010 7:40 pm
Posts: 25
Here is an update. I believe the script is complete, but it may need some minor adjustments.

Code:

#!/bin/bash

HOME=/home/user/scripts/bash/test
TMP=$HOME/tmp
LOGFILE=$HOME/wget.log
DATE=`date +%Y-%m-%d`
WGET="wget -P $TMP http://www.somesite.net/index.html"
MAIL="/usr/bin/mutt"
RECIP="user@email.com"

zip-file () {
    for i in $TMP/index.html; do
      zip -mj $TMP/backup_`date +%Y-%m-%d`.zip $i
       echo -n $DATE: file here... >> $LOGFILE
done
}

e-mail () {
    for z in $TMP/*.zip; do
     $MAIL -s "Daily Results" -a $z -- $RECIP < $LOGFILE
done
}

if [ ! -d $TMP ]; then
    mkdir $TMP
fi

if [ ! -f $TMP/index.html ]; then
    $WGET
fi

if [ -f $TMP/index.html ]; then
    zip-file;
     e-mail;
else
    echo -n $DATE: no file here... >> $LOGFILE
     $MAIL -s "Failed Update" $RECIP < $LOGFILE
exit 1
fi


I do see a lot of drive by posts, people make requests and never hear from them again!?

It also amazes me looking at the script, someone with experience am sure could have done this in less than 5 minutes and it took me 2 days, ofcourse, I do have a life you know.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP