Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Stick up your best shell scripts
Options
Comments
-
steveland? wrote:Sorry to butt in... but can someone please explain how to implement these scripts?
Most of the scripts given here can be put into a file and run directly,
in particular the scripts begining with:#!/bin/bash
This line should be the first line of the script or it will not work.
To run a file you require execute permissions on the file, which you can
achieve by setting the mode (or permissions) as follows:chmod 500 file
0 -
I use this to create .ISO backups of CDs & DVDs (doesnt work on copy protected content, unfortunately)
#!/bin/bash # cd copy script defpath="/usr/local/luna/public/shared/" permission="1444" # echo "This script will aid in copying a CD or DVD to disk" echo "please enter the location where you wish to save the" echo "disk ISO to, excluding the .iso file extension" echo echo -n "<install path:> $defpath" read usrpath echo mkdir -pv $defpath$usrpath dd bs="32" if="/dev/cdrom" of="$defpath$usrpath.iso" chmod -Rv $permission $defpath$usrpath eject
I have this run hourly, to set folder permissions (I have a shared folder availabe to all users on the windows network; without this, some files would become inacessible)#!/bin/bash # config host="luna" installpath="/usr/local/$host" # users usr[0]="public" usr[1]="usr1" usr[2]="usr2" usr[3]="usr3" usr[4]="usr4" # permissions - umask permit[0]="0777" permit[1]="0755" permit[2]="0755" permit[3]="0755" permit[4]="0755" function main() { # data members local i=0 while [ $i -lt 5 ]; do chmod "${permit[$i]}" -R "$installpath/${usr[$i]}" echo "${usr[$i]} - ${permit[$i]}" # increment i=$((++i)) done } ## main entry ## main
I also made a script (about 4 times now...) which downloaded the steam dedicated server from valve, checked for the prerequsit ncompress, extracted and installed it (never really got it finished though); I'll post it if I do it again, it can be a real bother to do it manually.0 -
#!/bin/bash dd if=/dev/cdrom bs=1 skip=32808 count=32 > /tmp/title DVDTITLE=`cat /tmp/title | awk '{print $1}' ` mplayer dvd:// -frames 1 -nosound -vo null > /tmp/mpr TITLENUM=`cat /tmp/mpr | grep "titles" | awk '{print $3}'` echo "DVD Label: $DVDTITLE Titles: $TITLENUM" mkdir $DVDTITLE for i in `seq 1 $TITLENUM`; do rm -f divx2pass.log frameno.avi mencoder -ovc xvid -xvidencopts pass=1:bitrate=1100 -nosound -vf pullup,pp=md dvd://$i -o /dev/null mencoder -ovc xvid -xvidencopts pass=2:bitrate=1100 -nosound -vf pullup,pp=md dvd://$i -o "/tmp/tmp.avi" mplayer -vo null -aid 128 -ao pcm:file="/tmp/tmp.wav" dvd://$i oggenc -q 3 "/tmp/tmp.wav" "/tmp/tmp.ogg" ogmmerge -o "./$DVDTITLE/Title $i.ogm" /tmp/tmp.avi /tmp/tmp.ogg done
This is a shell script for creating ogg media files(.ogm) from DVD in 2 pass xvid video and ogg audio , it takes each title and puts it into a seperate video file in a sub directory thats equal to the DVD label.
It uses mplayers mencoder to do the actual encoding. this takes quite a while!
So the dependencies of this script is ogm tools and mplayer with mencoder.0 -
Finally got around to making my own...
Well to be honest I nabbed it from someone else online but theirs had no user defined arguments, the max file size was hardcoded into the script, you couldn't execute the final command (it gave you an output of what the command should be)
Basically it'll ask you for the max file size you want it to use, what title on the DVD it should look for, what file you want to output to and how long the film is and then gives you an mencoder command to use to rip the title into DivX. It'll then prompt whether you want it to run the mencoder command for you. Been using this for a while and it's dead handy.
It'll save the file to /home/$USER/Videos/<thefilenameyouspecified>.avi
[php]#!/bin/bash
echo "Welcome to the DVD Ripper Wizard"
echo "
"
echo "Please enter the maximum filesize you want your file to be (in MB)"
read MAXFILESIZE
echo "Please enter the Title at which the movie starts on the DVD"
read CHAPTER
echo "Please enter the output file you desire (without .avi)"
read OUTPUTFILE
echo "Please enter how long the movie is (in minutes, round to the nearest)"
read MINUTES
MAXSIZE=$((1000*$MAXFILESIZE))
SECONDS=$((60*$MINUTES))
AUDIOSIZE=$((20*$SECONDS))
FRAMES=$(($MAXSIZE - $AUDIOSIZE))
RATE=$((($FRAMES*8) / $SECONDS))
FINALSIZE=$(( (($RATE * $SECONDS)/8 + $AUDIOSIZE) /1000 ))
echo "
"
echo "Estimated Rate: $RATE Kb/s"
echo "Estimated Filesize: $FINALSIZE MB"
echo "
"
echo ""
echo "The following command will be used:"
echo "mencoder dvd://$CHAPTER -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=$RATE -vop scale -zoom -xy 640 -oac mp3lame -lameopts abr:br=128 -o /home/$USER/Videos/$OUTPUTFILE.avi"
echo ""
echo "
"
echo "Do you wish to run this command now? (y/n)"
read runnow
if [ $runnow == y ]; then
echo "Running now!"
# run the command!
mencoder dvd://$CHAPTER -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=$RATE -vop scale -zoom -xy 640 -oac mp3lame -lameopts abr:br=128 -o /home/steve/Videos/$OUTPUTFILE.avi
exit -1
elif [ $runnow == n ]; then
echo "Not Running"
exit -1
else
echo "Command not recognised, exiting"
exit -1
fi[/php]0 -
something i whipped up in work to run through a load of test cases in a test that i was doing, so that i could have tagged output that i could grep through to generate my gnuplot plots.
[PHP]
#!/bin/bash
#PBS -N cpmd-IB
#PBS -q parallel
#PBS -l walltime=96:00:00,cput=6144:00:00
#PBS -l nodes=32:ppn=2
#
# CPMD test case si63-120ryd, where MAXCPUTIME=93600
#
#
#setup some variables
#
D=`date +"%Y-%m-%d--%H-%M-%S"`
O=OUT__${D}
#
# location of the CPMDBIN
#
CPMDBIN=/usr/support/CPMDToolBox-3.9.2/bin/cpmd.x
#
# go to my job submission directory and then execute the program
#
cd $PBS_O_WORKDIR
#
# loop over benchmark cases (test scaling of cpmd over interconnect)
#
for i in 1 2 4 8 16 32 64
do
echo "== NODES $i ==" > ${O}-$i
echo "==============" >> ${O}-$i
date >> ${O}-$i 2>&1
echo "==============" >> ${O}-$i
mpiexec -n $i /usr/support/CPMDToolBox-3.9.2/bin/cpmd.x inp.wf.full >> ${O}-$i 2>&1
echo "==============" >> ${O}-$i
date >> ${O}-$i 2>&1
echo "==============" >> ${O}-$i
sleep 30
done
[/PHP]0 -
Advertisement
-
Very simple script for converting image resolution.
#!/bin/sh for img in `ls *.JPG` do convert -resize 1024x768 $img resized-$img done
0 -
rm -rf0
-
sicruise wrote:rm -rf
.
.
.
.
.
.
.
.
.
.
.
.
.
Not0 -
Now, apologies for the cross-post but thought the finished product would be suited to this little archive of scripts.
I have it set to run every 15 minutes to randomly change my desktop.
Thanks to angelofdeath and generalmiaow for their help with this one.
[php]#!/bin/bash
DIRECTORY=/home/steve/Pictures/RandomDesktops/ # the directory with your files in it
# This directory can only contain image files!
DIRECTORYCOUNT=`ls $DIRECTORY | wc -l` # counts the files in your chosen directory
VARIABLE=$[($RANDOM % $DIRECTORYCOUNT) + 1] # find a random element
if [ $VARIABLE = 0 ] ; then # can't find the 0th file, returns 2
VARIABLE=2
fi
# Now load each of the files in the directory into an array
i="1"
for fileName in `ls $DIRECTORY`
do
array[$i]="$fileName"
i=`expr $i + 1`
done
gconftool-2 -t str --set /desktop/gnome/background/picture_filename $DIRECTORY${array[$VARIABLE]}
gconftool-2 -t str --set /desktop/gnome/background/picture_options "stretched"
[/php]0 -
A very simple one for a task I do often.
#! /bin/bash # apup: script to upgrade system if [ "$1" = "-d" ]; then echo "dist-upgrade" sudo aptitude update && sudo aptitude dist-upgrade else echo "regular upgrade" sudo aptitude update && sudo aptitude upgrade fi
$ apup regular upgrade Password: Reading package lists... Done Building dependency tree... Done Reading extended state information Initializing package states... Done Building tag database... Done etc...
$ apup -d dist-upgrade Password: Reading package lists... Done Building dependency tree... Done Reading extended state information Initializing package states... Done Building tag database... Done etc...
steveland? Couldn't you usefor fileName in `ls $DIRECTORY | egrep -i ".jpg|.gif|.png|.bmp|.svg"`
That way you'd solve the bug of having to have only image files in the directory.0 -
Advertisement
-
Wrote this to keep me updated when my ip address is changed so I can connect to my home computer from elsewhere. It also reboots the router when it disconnects from the internet, which it does from time to time. It's crude but it works. I'm not sure rebooted variable is working properly. It's my first perl experience!
#!/usr/bin/perl use Net::Telnet; use Net::Ping; $remote_host = 'some.remote.site'; $local_host = 'router.local.address'; $log_file = '/var/log/router_mon'; $remote_ping = Net::Ping->new(); $rebooted = 0; if(!$remote_ping->ping($remote_host)){ while (!$remote_ping->ping($remote_host)) { $local_ping = Net::Ping->new(); exit 0 if !$local_ping->ping($local_host); $t = new Net::Telnet(); $t->open($local_host); $t->print('admin'); $t->waitfor('/Password:/'); $t->print('my_password'); $t->waitfor('/Belkin>/'); $t->print('reboot'); $t->close(); while (!$local_ping->ping($local_host)) { sleep(20); } $local_ping->close(); $t->close; $rebooted++; } $remote_ping->close(); } $t = new Net::Telnet(); $t->open($local_host); $t->print('admin'); $t->waitfor('/Password:/'); $t->print('my_password'); $t->waitfor('/Belkin>/'); $t->print('ifconfig ppp0'); $t->waitfor('/has_ip=/'); $t->waitfor('/ip=/'); ($ip_addr, $match) = $t->waitfor('/,/'); $t->print('exit'); $t->close; open (FH, "+< $log_file") or die; while ( $line= <FH> ) {$ip_old = $line;} chomp $ip_old; if(!($ip_old eq $ip_addr)){ print FH "$ip_addr\n"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $to='my_email_address@gmail.com'; $from= 'my_email_address@gmail.com'; $subject = sprintf("new server ip %s",$ip_addr); $body = sprintf("system rebooted %u times at %u:%u on the %u/%u/%u, ip address obtained was: %s.",$rebooted,$hour,$min,$mday,$mon,$year+1900,$ip_addr); open(MAIL, '|/usr/sbin/sendmail -t'); print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n"; print MAIL "Content-type: text/plain\n\n"; print MAIL "$body \n\n"; close(MAIL); } close FH;
Oh cron runs it every ten mins.0 -
Haha! I didn't realise humbert's was a perl script for a whole minute and got very confused. Looks like a great hack though. I have a bash script that more or less the same thing (except it wgets a php script on my site which records my IP in a databse). I must try building in the power to reboot my router (same problem, and also a telnettable linksys router). No idea whether I can send telnet commands from a bash script but I imagine it's possible0
-
Heres a small bit of shell for drawing one of those progress spinners...
#!/bin/sh I=0 SPIN="[= ]" echo -n "DEBUG: Test running ${SPIN}" while [ $I -lt 60 ] do tput cub 13 case $SPIN in "[= ]") SPIN="[ = ]";; "[ = ]") SPIN="[ = ]";; "[ = ]") SPIN="[ = ]";; "[ = ]") SPIN="[ = ]";; "[ = ]") SPIN="[ = ]";; "[ = ]") SPIN="[ = ]";; "[ = ]") SPIN="[ = ]";; "[ = ]") SPIN="[ = ]";; "[ = ]") SPIN="[ = ]";; "[ = ]") SPIN="[ =]";; "[ =]") SPIN="[= ]";; esac echo -n "${SPIN}" sleep 1 I=`expr $I + 1` done tput cub 13 echo "[===DONE!===]"
0 -
Right since your all sticking up scripts does anyone know a script to communicate with meteor.ie to send the free texts.I've seen it been done so i know its possible.I just cant find it anywhere.Just wondering if somebody here might have had one or know where to get one.0
-
Right since your all sticking up scripts does anyone know a script to communicate with meteor.ie to send the free texts.I've seen it been done so i know its possible.I just cant find it anywhere.Just wondering if somebody here might have had one or know where to get one.
http://mackers.com/projects/o2sms/
Supports, o2, voda, meteor. It's a cracking wee script.0 -
Nice one cheers0
-
Didn't know that was working with meteor... the one on the NUIG compsoc server isn't, so I ended up writing my own one, has only basic features but is EASILY adapted to changes and to other networks.
You can get a copy hnyah:
http://compsoc.nuigalway.ie/~grasshopa/meteor20 -
Ah, shell scripting, sounds daunting, but its a very useful & powerful thing
Here's one I was messing around with a long time ago, on Ubuntu 6.10, I actually haven't messed around (with scripts) since then TBH.
Its to do with the 'FIND' command.
The 'xdev' lets me just search the local drive/linux partition.
This version was one of my first attempts, I did modify it to suit my needs later.
#!/bin/sh
echo clear
echo "Enter 1 for Word-Find program:"
echo "Enter 2 for File-Find program:"
read a
if [ "$a" -eq "1" ]
then
echo "Enter search WORD:"
read w
echo "Enter /path/file to search:"
read p
# insensitive search, recursive, show only file name
grep -irl $w $p
elif [ "$a" -eq "2" ]
then
echo "Enter search FILE:"
read f
echo "Enter /path/ to search:"
read pa
find $pa -xdev -type f -iname $f
else
echo "Wrong choice !"
fi
exit $?0 -
Here's a nice script that downloads the xkcd comic archive. It's in perl and requires wget, but I'd imagine all distros have perl, so I'm going to call it a shell script :P
#!/usr/bin/perl #Downloads the xkcd archive from http://imgs.xkcd.com/comics/ #Released for totally free use for anyone who wishes to! @args1 = ("wget","http://imgs.xkcd.com/comics/"); system(@args1); #call wget to get the html of the list open (FILE, "<index.html") or die($!); foreach(<FILE>){ if (/<tr><td class="n">/){ #only the lines that are links to comics contain this string s/.*?>.*?>.*?>(.*?)<.*/$1/; #regex strips html and leaves behind "the_comic_name.png" print "$_\n"; chomp ($comic = $_); #get rid of trailing newline character @args2 = ("wget","http://imgs.xkcd.com/comics/"."$comic"); print "Obtaining $comic..\n"; system(@args2); #get the actual comic print "[OK]\n"; } } close FILE or die($!); @args3 = ("rm","index.html"); #erase the html page so script will work next time system(@args3);
And here's a similar script to download the current xkcd comic. I guess you'd run the above, then cron the below to run every Monday, Wednesday, Thursday!#!/usr/bin/perl @args1 = ("wget","http://xkcd.com/"); system(@args1); #call wget to get the html open (FILE, "<index.html") or die($!); foreach(<FILE>){ if (/<h3>Image URL/){ #find the link for hotlinking s/.*?: {1}(.*?)<.*/$1/; #strip html chomp; print "Obtaining comic.."; @args2 = ("wget","$_"); system(@args2); print "[OK]\n"; } } close FILE or die($!); @args3 = ("rm","index.html"); #erase the html page so script will work next time system(@args3);
Comments are more than welcome.0 -
Not a shell script, but a shell script request. Apologies if misposted.
I've just migrated full time to Ubuntu 8.04/ LinuxMint on my laptop as my Apple G4 tower has 'died'.
Anyway, I have all my photos backed up in Time Machine, which is fine if you have another Mac to get them off. I don't. I found the following article on how to find an individual file (the problem is something to do with hardlinks).
http://carsonbaker.org/2008/06/23/time-machine-restore/
Anyway, the way that iPhoto stores the photos results in hundreds/ thousands of hard links. So I'm looking for a script to 'extract' all the photos from the Time Machine disk and copy them to the laptop.
I'd like to leave the Time Machine intact in case I do get another Mac.
All help appreciated.
G.0 -
Advertisement
-
I present a little app I came up with while messing around with conky. As you may know, that involves editing a file, running conky, killing it from the gnome-system-monitor, then editing agian.. It gets tedious. So, I wrote this perl script that acts like the "kill" command, but based on process name, not PID.
#!/usr/bin/perl #Kill the process named as the first argument. my $doomed = @ARGV[0]; #get the name of the process open (FILE, ">processes.txt") or die($!); print (FILE `ps -e`); #get list of processes close FILE,open (FILE, "<processes.txt") or die($!); foreach(<FILE>){ if (/$doomed/){ #find line with the selected process /(.*?)\s/; #get the PID print"Killing $doomed with a PID ". "of $1..\n"; $pid = $1; #the PID @args= ("kill","$pid"); $status = system(@args);#try to kill and capture #exit status if ($status eq "0"){ print "Killed.\n"; exit;#end the program }else{ die("Unable to kill $doomed.\n"); } } } #only way to get here is to not have died- meaning the if statement #was never entered, hence: print "No process named $doomed found currently running.\n";
And some sample output:karlreid@karlreid-laptop:~$ killthis conky Killing conky with a PID of 24584.. Killed. karlreid@karlreid-laptop:~$
It can kill root processes too(obviously, be careful ):karlreid@karlreid-laptop:~$ sudo conky [sudo] password for karlreid: Conky: /home/karlreid/.conkyrc: 7: config file error Conky: use_spacer should have an argument of left, right, or none. 'yes' seems to be some form of 'true', so defaulting to right. Conky: diskio device '19' does not exist Conky: forked to background, pid is 24749 karlreid@karlreid-laptop:~$ Conky: desktop window (10000b4) is subwindow of root window (13b) Conky: window type - normal Conky: drawing to created window (3200001) Conky: drawing to double buffer karlreid@karlreid-laptop:~$ killthis conky Killing conky with a PID of 24749.. Unable to kill conky. karlreid@karlreid-laptop:~$ sudo ~/bin/killthis conky Killing conky with a PID of 24749.. Conky: received SIGINT or SIGTERM to terminate. bye! Killed. karlreid@karlreid-laptop:~$
karlreid@karlreid-laptop:~$ killthis nonexistentprocess No process named nonexistentprocess found currently running. karlreid@karlreid-laptop:~$
0 -
good exercise in script writing, but I think you should know about a command named "pkill" sometimes (BSD) "killall" ....0
-
:hmm, killall conky ... :O:
:Hangs head in abject embarrassment and shame::o
Ah well, it was fun!0 -
Generates a random password / passphrase:
#!/bin/bash M="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" L="8" while [ $L -gt 0 ] do PASS="$PASS${M:$(($RANDOM%${#M})):1}" let L-=1 done echo "$PASS"
0 -
Two scripts i cut in half and then joined to improve on the original:
It'll rip the audio from a youtube url and leave it on your desktop in mp3.
Depends on youtube-dl and ffmpeg#!/bin/bash
cd ~/
read -p "YouTube url? " ur
read -p "Name? One word only!! " nv
echo;echo;
youtube-dl -o ${nv} "${ur}"
ffmpeg -i "${nv}" -acodec libmp3lame -ab 160k -ac 2 -ar 44100 "${nv}.mp3"
mv "${nv}.mp3" ~/Desktop/"${nv}.mp3"
rm ${nv}
echo;echo;
echo "Your new MP3 file is saved on your Desktop."
read0 -
This goes out to a bunch of websites and downloads the webcomics.
Run it once a day at 10am to get them delivered to your inbox....#!/bin/sh MAILTO="your.email@address.here" ######################################################################################## ## Setup Proxy - if you need one, otherwise comment this line out ######################################################################################## export http_proxy='http://1.2.3.4:8080' ######################################################################################## ## Penny Arcade - Nerd/Gamer Humour ######################################################################################## URLBASE="http://www.penny-arcade.com" wget -O page.html ${URLBASE}/comic/ IMGURL=`grep simplebody page.html | awk -F'"' '{print $4}'` wget -O pennyarcade.jpg ${URLBASE}/${IMGURL} ######################################################################################## ## Dilbert - IT Work Humour ######################################################################################## URLBASE="http://www.dilbert.com" wget -O page.html ${URLBASE} IMGURL=`grep -A1 STR_Content page.html | tail -1 | awk -F'"' '{print $4}'` wget -O dilbert.gif ${URLBASE}/${IMGURL} ######################################################################################## ## XKCD - Geek Humour ######################################################################################## URLBASE="http://xkcd.com" wget -O page.html ${URLBASE} IMGURL=`grep -A7 rnd_btn_t page.html | tail -1 | awk -F'"' '{print $2}'` wget -O xkcd.png ${IMGURL} ######################################################################################## ## Dinosaur Comics - Bizzare Humour ######################################################################################## URLBASE="http://www.qwantz.com" wget -O page.html ${URLBASE} IMGURL=`grep 'qwantz.com/comics/' page.html | grep -v facebook | awk -F'"' '{print $2}'` wget -O dc.png ${IMGURL} ######################################################################################## ## Redmeat - Bizzare Humour ######################################################################################## URLBASE="http://www.redmeat.com/redmeat/current" wget -O page.html ${URLBASE}/index.html IMGURL=`grep -A1 'weeklyStrip' page.html | tail -1 | awk -F'"' '{print $2}'` wget -O redmeat.gif ${URLBASE}/${IMGURL} ######################################################################################## ## Least I could do.... ######################################################################################## URLBASE="http://www.leasticoulddo.com" wget -O page.html ${URLBASE}/ IMGURL=`grep -A1 'comic' page.html | grep 'archive.leasticoulddo.com' | tail -1 | awk -F'"' '{print $2}'` wget -O licd.gif ${IMGURL} ######################################################################################## ## Garfield Minus Garfield ######################################################################################## URLBASE="http://garfieldminusgarfield.net/" wget -O page.html ${URLBASE}/ IMGURL=`grep "media.tumblr" page.html | awk -F'"' '{print $4}' | head -1` wget -O garfieldminusgarfield.png ${IMGURL} ######################################################################################## ## Bigger than Cheeses ######################################################################################## URLBASE="http://www.biggercheese.com/" wget -O page.html ${URLBASE}/ IMGURL=`cat page.html | grep -A1 OnlineComics.net | grep img | awk -F'"' '{print $4}'` wget -O btc.png ${URLBASE}/${IMGURL} ######################################################################################## ## Cyanide and Happiness ######################################################################################## URLBASE="http://www.explosm.net/comics/" wget -O page.html ${URLBASE}/ IMGURL=`cat page.html | grep Archive | awk -F'"' '{print $32}'` wget -O cah.png ${IMGURL} ######################################################################################## ## PvP ######################################################################################## URLBASE="http://www.pvponline.com/" wget -O page.html ${URLBASE}/ IMGURL=`grep 'pvponline.com/comics' page.html | awk -F'"' '{print $2}'` wget -O pvp.gif ${IMGURL} ######################################################################################## ## Email the comics ######################################################################################## echo "Hullo," > body.txt echo >> body.txt echo "Please find attached your daily dose of comic humour" >> body.txt echo >> body.txt echo "Todays batch includes:" >> body.txt echo >> body.txt echo " * Penny Arcade" >> body.txt echo " * Dilbert" >> body.txt echo " * Dinosaur Comics" >> body.txt echo " * XKCD" >> body.txt echo " * Redmeat" >> body.txt echo " * Least I could Do" >> body.txt echo " * Garfield minus Garfield" >> body.txt echo " * Bigger than Cheeses" >> body.txt echo " * Cyanide and Happiness" >> body.txt echo " * PvP (Player vs Player)" >> body.txt echo >> body.txt echo "If you have a favourite comic you'd like added, let Dave know..." >> body.txt echo >> body.txt echo "Regards" >> body.txt echo "Daves Comic Trawling Web Monkey" >> body.txt cat body.txt | mutt -s "Comics for today - `date -I`" -a pennyarcade.jpg -a dilbert.gif -a xkcd.png -a dc.png -a redmeat.gif -a licd.gif -a garfieldminusgarfield.png -a btc.png -a cah.png -a pvp.gif $MAILTO ######################################################################################## ## Clean up ######################################################################################## rm -f body.txt page.html *.jpg *.png *.gif
Should work on any liux box with mutt and wget installed :-)0 -
Heres one in a similar vein to the one i posted above but that i wrote myself.
It works by exploiting the way firefox stores flash files in the /tmp/ folder.
To use it open the youtube, dailymotion, etc page you want to acquire the song from, assuming its open licensed of course and wait until the video loads fully and then simply run the script. This will work with multiple tabs as well.#!/bin/sh
find /tmp -maxdepth 1 -name "Flash*" -type f -prune -exec ffmpeg -i '{}' -acodec libmp3lame -ab 160k -ac 2 -ar 44100 '{}.mp3' \;
find /tmp -maxdepth 1 -name "*.mp3" -prune -type f -exec mv '{}' ~/Desktop/ \;0 -
Here's one that'll replace the spaces in filenames with an underscore. It's handy if you want to loop one program through a directory that doesn't like spaces in filenames.
if [ -n "$1" ] then if [ -d "$1" ] then cd "$1" else echo invalid directory exit fi fi for i in * do OLDNAME="$i" NEWNAME=`echo "$i" | tr ' ' '_' | tr A-Z a-z | sed s/_-_/-/g` if [ "$NEWNAME" != "$OLDNAME" ] then TMPNAME="$i"_TMP echo "" mv -v -- "$OLDNAME" "$TMPNAME" mv -v -- "$TMPNAME" "$NEWNAME" fi if [ -d "$NEWNAME" ] then echo Recursing lowercase for directory "$NEWNAME" $0 "$NEWNAME" fi done
0 -
Here's one that'll replace the spaces in filenames with an underscore. It's handy if you want to loop one program through a directory that doesn't like spaces in filenames.
<snip>
Decent script, but slightly redundant:
Usage: rename <thing-to-match> <thing-to-replace-it-with> <filelist>
So, for example:
shell$ rename ' ' '_' *0 -
Advertisement
-
This is really the only proper shell script I ever scripted. It worked in Ubuntu 9.04 for me. Apologies if its crap and if youve any criticism hit me with it
This script takes a C++ source file, compiles it, and then runs it. It works under a strictish naming convention. The source file is $1.cpp and then the output is $1.
Any further parameters will be passed onto the program. Example:
$ ./cr.sh helloWorld "param 1" "param 2"
This will compile ./helloWorld.cpp to ./helloWorld using g++, then run
$ ./helloWorld "param 1" "param 2"
If the source code is older than the compiled code, that is to say the source hasnt been updated since the last compile, then it skips compiling and just runs the compiled file. Handy for testing through terminal (which is how Im learning C++)#!/bin/sh #Script to compile and run C++ source file # ./cr.sh [source filename without .cpp extension] [arguments to be passed to compiled program] #Check if file exists if [ ! -e "$1.cpp" ] then echo "Error: $1.cpp not a file!" exit 1 fi #Does program file exist? If not compile. if [ ! -e "$1" ] then g++ ./$1.cpp -o $1 else #Has source been modified since last compile? If so compile if test $(stat --format=%Y $1) -lt $(stat --format=%Y $1.cpp) then g++ ./$1.cpp -o $1 fi fi #Grab arguementes to pass to C++ program TEMP=`echo $* | awk '{print substr( $0, index($0," ")+1, length($0)-index($0," ")+1 ) }'` if [ ! -e $2 ] then ./$1 $TEMP else ./$1 fi
Any comments such as better error handling will be really appreciated0
Advertisement