LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 12-13-2010, 09:04 AM   #16
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208

Quote:
Originally Posted by H_TeXMeX_H View Post
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!
 
Old 12-14-2010, 06:48 AM   #17
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The coolest for me is maybe a 850 line sed script to add extensions to files based on the output of the file command.
http://www.linuxquestions.org/questi...0&d=1264088884

Run like:

find . -not -name "*.*" -printf "%f\n" | tr '\n' '\0' | xargs -0 file -i | sed -f addext.sed >add_extensions.sh

to generate a script to rename the files.
 
Old 12-14-2010, 06:51 AM   #18
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by H_TeXMeX_H View Post
Hmm, so you consider that a cool script ?
It is when it's your first
 
Old 12-14-2010, 06:53 AM   #19
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by szboardstretcher View Post
I made a script once that would go through a directory of pictures, finding similar (resized or resampled) pics ...
Which tools did you use to do the re-sized or re-sampled part?
 
Old 12-14-2010, 07:28 AM   #20
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
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.

I posted my wrapper for ufsdump on the Amanda wiki at http://wiki.zmanda.com/index.php/Bac...yk.27s_Example.

I posted a simple example of what I think of as cool scripting on http://blogs.umass.edu/choogend/2007...list-sysadmin/ and another example that involved getting into Mac OS X's launchd and plists to automatically start up screen to work as a remote console for my servers -- http://blogs.umass.edu/choogend/2008/05/23/ammonoidea/

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.
 
Old 12-17-2010, 07:19 PM   #21
firehak
LQ Newbie
 
Registered: Dec 2009
Location: North Canton, OH
Distribution: Fedora
Posts: 13

Rep: Reputation: 0
Quote:
Originally Posted by crts View Post
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.

Last edited by firehak; 12-17-2010 at 07:28 PM.
 
Old 12-17-2010, 09:42 PM   #22
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
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
  1. Declare a variable for today's date/hour/minute.
  2. Use the variable to create a directory in my backups directory.
  3. Use mysqldump to backup my blog mysql database to that directory.
  4. Shutdown my webserver (I was using the Xampp stack at the time).
  5. Gzip my log files to the backup directory.
  6. 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
 
Old 12-18-2010, 12:31 AM   #23
leehanken
LQ Newbie
 
Registered: Jan 2009
Posts: 14
Blog Entries: 1

Rep: Reputation: 7
Script

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.

http://www.linuxquestions.org/questi...coration-3438/
 
Old 12-19-2010, 12:12 PM   #24
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
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
 
Old 01-09-2012, 02:26 PM   #25
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928

Original Poster
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
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.
 
Old 01-09-2012, 03:07 PM   #26
linux-freak
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Rep: Reputation: Disabled
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.
 
Old 01-09-2012, 03:08 PM   #27
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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.
 
Old 01-10-2012, 07:30 AM   #28
markseger
Member
 
Registered: Jul 2003
Posts: 244

Rep: Reputation: 26
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
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is the best scripting language? kike_coello Programming 22 07-25-2009 05:16 PM
event.d scripting language? Hourani Linux - Newbie 3 02-02-2009 04:39 PM
LXer: Scripting SSH and SFTP Made Easy With Python LXer Syndicated Linux News 0 12-17-2008 12:20 AM
Best scripting language? walterbyrd Linux - Software 2 01-08-2006 02:13 PM
Which Scripting Language? birdseye Programming 2 10-03-2005 09:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:28 PM.

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