Articles, Tutorials, and other things. => General Programming => : Richard Marks March 07, 2009, 10:40:04 PM

: Linux Shell Scripts
: Richard Marks March 07, 2009, 10:40:04 PM
Linux Shell Scripts

This script makes it easy to find out if something is installed and get its version info.

#!/usr/env ruby
# DoIHave.rb
# a simple script for checking if something is installed
# Developed by Richard Marks <>
# depends on having aptitude installed
@packageName = $*
@command1 = %(aptitude show #{@packageName} 2> /dev/null | awk '/State/ {print $2" "$3}')
@command2 = "aptitude show #{@packageName} 2> /dev/null | awk '/Version/ {print $2}'"
@haveIt = `#{@command1}`
if @haveIt.length then
@haveVersion = `#{@command2}`
puts "#{@packageName} is #{@haveIt}version #{@haveVersion}"
puts "#{@packageName} is #{@haveIt}"

Place it on your PATH and invoke it with the name of what you are looking for:
$ DoIHave ruby1.9
ruby1.9 is not installed
$ DoIHave git
git is installed
version 4.3.20-12

If you have any cool shell scripts, go ahead and post them!

: Re: Linux Shell Scripts
: Richard Marks March 07, 2009, 11:07:27 PM
A sweet little one-liner for creating really strong random passwords.
$ echo $(tr -dc "a-zA-Z0-9-_\$\+\-\?" < /dev/urandom | head -c 24)

Change the -c 24 part to change the length of the password.

$ echo $(tr -dc "a-zA-Z0-9-_\$\+\-\?" < /dev/urandom | head -c 24)
$ echo $(tr -dc "a-zA-Z0-9-_\$\+\-\?" < /dev/urandom | head -c 24)
$ echo $(tr -dc "a-zA-Z0-9-_\$\+\-\?" < /dev/urandom | head -c 24)

: Re: Linux Shell Scripts
: Richard Marks March 08, 2009, 12:31:14 AM

A nifty "little" script to get your computer to wake you up. ;D
Paste this in an open terminal window, and use CTRL+C to kill your alarm when it wakes you.
$ $(TTDELAY=8h; CURTIME=`date "+%c"`; sleep $TTDELAY; TTC=0; TTCM=10; while [ $TTC -lt $TTCM ]; do espeak -p 100 -s 120 "Wake up" ; let TTC=TTC+1; done; zenity --info --text="You wanted to wake up.\n `date "+%c"` \nYou set this timer $CURTIME.\n\n I tried to call you $TTCM times\!")

Vars to change:

TTDELAY=8h set the time for the timer to 8 hours (a good night's rest)
TTCM=10 set the number of times for the 'alarm' to sound

Sorry, the copyright must be in the template.
Please notify this forum's administrator that this site is missing the copyright message for SMF so they can rectify the situation. Display of copyright is a legal requirement. For more information on this please visit the Simple Machines website.