What is the coolest script you've made ? Any scripting language.
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Well, cool = even you amazed by what you could do. I didn't think it was possible to write some of these scripts that I wrote, but I did it.
OK then, an example -- using udev rules to start a script to mount a USB HDD when it is plugged in (but not if it happens to be plugged in during boot), fsck it if necessary, stop the Bacula (backup system) daemons, rsync disaster recovery files to it including Bacula data, restart the Bacula daemons (if they were not already stopped when the script started), unmount the HDD file system and pop up a GUI window to tell the user it has finished, all with logrotated logging (syslog at the highest level, file for detail) unless being run from the command line (debugging) in which case logging to screen. But the most amazing thing was not being able to stop the HDD spinning!
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
Can't remember them all at the moment, but I get a charge out of being able to do something in a single line using combinations of unix utilities (sed, awk, grep, wc, and others) and pipes. When I was taking a class on Unix utilities, we had an assignment with a half hour to do it. I puzzled it out into a single line with a regular expression and spent most of the half hour experimenting with other things. When the time was up, the instructor showed us the "official" solution, which was a full page of shell script.
I don't always do it that way. One script I've had in daily use for a few years now across a fair number of systems is a wrapper for ufsdump. From the outside (called by Amanda), it looks just like ufsdump. If it is called to do an estimate, it simply passes the request to ufsdump and returns the results. If it is called to actually do a dump, it does an fssnap snapshot first and then dumps the snapshot. Of course, it has to deal with all the nuances of snapshots having to be on a different partition, fssnap of root requiring that there be no realtime processes running (so shutdown xntpd before and start it up after), and so on. On Solaris 10, it had to be adapted to work with SMF.
If anyone wants a real challenge, I don't think a solution has ever been submitted for this -- http://code.v.igoro.us/archives/8-Pr...Generator.html. I've been tempted, because I've done both PostScript programming and a lot of sodoku as well as game programming, but I just don't have the time to dedicate to it.
Oh, and speaking of PostScript, way back in the days (1987), when all that stuff was pretty new, I got a job to design a logo. Several graphic artists had come up with attempts that were rejected. The guy had clearly in mind a high tech rendition he wanted. I wrote a PostScript program with logarithmically scaled lines that I could tweak until the results worked on a LaserWriter. Then I ran it out on a Linotronic Imagesetter on film. He was beaming when he saw the final output. That was a real kick.
A couple of weeks ago I wrote a script to automate my LFS build. It extracts all the commands from the XML file and puts the commands necessary to build a package in their own dedicated script. Afterwards you can run the script and save yourself some tedious typing.
I know, there are already scripts to automate an LFS build. However, it was a nice exercise.
I've been doing the same thing for a fun project. I wanted to see how well I could manage a somewhat larger script. I really liked the Arch Installation Framework, so I've been teaching myself to do terminal GUI's with dialog and making step by step menus. I even ended up making a GitHub account to manage it.
EDIT: I'd like to have a script for configuring the finished LFS system too, if it works when I'm done.
Back when I was self-hosting my website, the log files started to drag down my server (Pentium 4). I also had a database crash.
I wrote a script to
Declare a variable for today's date/hour/minute.
Use the variable to create a directory in my backups directory.
Use mysqldump to backup my blog mysql database to that directory.
Shutdown my webserver (I was using the Xampp stack at the time).
Gzip my log files to the backup directory.
Restart my webserver.
It took me two days and lots of experimentation to make it work. I could not have done it without this manual.
Since I am not a coder (the closest I've come to coding is writing Telemate scripts to download messages, a few PCBoard scripts back in the BBS days, and a few *.bat files), I was really proud of myself.
(Telemate was a com program for DOS and Windows 3.1; PCBoard was the best BBS software ev-uh.)
Last edited by frankbell; 12-17-2010 at 09:46 PM.
Reason: clarity
Not really one script, but a few linked. To display email, facebook and rss feeds scrolling on a wall mounted laptop. Bit of a waste of time, but I was stuck indoors due to heavy snow.
Most of what I do with bash is either interactive or pointless ()
Here's a small thing I did that plays an audio file faster and faster at a user-specified starting speed and increments.
wavaccel.sh, in all its cheap, amateurish, pointless glory:
Code:
#!/bin/bash
if [ $1 ]; then
if [ $6 -lt 5 ]; then
let "r = 5"
else
let "r = $6"
fi
for ((x = $3; x < $5; x++)); do #whole step
for ((y = $4; y < 100; y += $r)); do #fractional step
play -q -v $1 $2 speed $x.$y
done
done
else
echo "Usage: ./wavaccel.sh <vol> <filename> <whole> <frac> <max> <step>"
echo "Plays an audio file faster and faster according to user parameters"
fi
(requires SoX)
I mostly wrote it for learning purposes...and because I was bored. It obviously(?) isn't perfect; due to the fact that it takes the integer and fractional part of the speed value separately, it jumps to an incorrect speed every time it reaches a new integer (e.g. from 1 to 2) if you specify a non-integer starting value.
That said, I do actually have a couple useful scripts for connecting/disconnecting to my home wireless, but those are pretty simplistic (really the only "special" thing they do is check for root perms ).
Last edited by MrCode; 12-19-2010 at 12:21 PM.
Reason: removed "debugging" echo
Yeah, this thread is somewhat old, but I have to post it because I feel proud of two scripts I wrote recently (both are on my site).
Basically, they are wrapper scripts for p7zip (7z) that use Xdialog to provide a gui for creating and extracting archives. I made it because other ones have many dependencies and don't work too well, sometimes stuff extracts all over the place and sometimes things are nested two levels deep. I've solved both these problems and it works exactly like I want it to. They can be ported to any dialog-compatible program like zenity and kdialog, but I can't test these so I didn't include a mechanism to switch to them. I didn't know that this could be done with just scripting, so I think these qualify as cool scripts.
Oh, and there's also the defrag scripts I wrote. I know others have wrote similar ones, but I've tried them and they don't work like I want them to.
I have 30 bash scripts in my home bin folder. They range from multimedia to system tasks. I have one script that records from the TV turner card using mencoder.
This is why I love using linux. You can make your own scripts to do specific tasks around linux programs.
Last edited by linux-freak; 01-09-2012 at 03:27 PM.
I didn't see this thread on the first go-round, but I wrote a long script to automate image downloads from various sites that I had memberships with (e.g. DigitalBlasphemy).
It started out as a simple hand-typed list of images to download from DigitalBlasphemy that was fed to wget. Then I continued to add functionality. When it was all said and done, the script:
1. Logged into multiple websites
2. Downloaded the list of galleries
3. Parsed the galleries for image download links
4. Downloaded images based on pre-determined criteria (e.g. image format, image creator, genre: nature, fantasy, etc.)
5. Moved the downloaded images to a centralized and standardized website-artist-gallery filesystem structure
6. Created a standard size thumbnail of the downloaded image
7. Added mysql records to a database with the pathname to the image, criteria tags, resolution, color depth, date and time downloaded, website downloaded from, etc.
The database had two uses--to provide the data backend for:
1. a locally-served PHP website (to navigate through the image types--a photo album of sorts)
2. another simple script that would submit an SQL query for filenames of images meeting criteria and send those filenames to feh for a slideshow (e.g. space pictures, nature images, family, etc.)
Anyway, because of its simple beginnings with wget, it started as a bash script. At some point I should have converted it to another scripting language, but all of the above can (and was) done with bash and standard tools.
I guess for me it was collectl! The original plan was to prototype it in perl and then port it to C, but perl turned out to be so efficient it didn't seem worth the effort.
-mark
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.