Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Friday, December 31, 2010

Command Line Init Script Generator For Linux Or Unix

Hey There,

To start this week off, we've got another updated script (now that we have over 600 some odd posts, we actually have about 400 some odd loose ends to finish up, as well ;) This script is an update of an earlier post we did to showcase a basic init script generator for Linux or Unix, again hearkening back to 2007. How time flies when you're not paying attention to what you're doing ;)

This script includes several updates (which haven't been tested to perfection - so feel free to write in with complaints ;) such as the ability to use command line arguments to specify a wider variety of options, set some to default and not even enter any (except three) if you don't want to. Actually, the only three required arguments are the name of the program you want to start with the init script you generate, the fully qualified name of the same program and the name of the init script itself. All the other options are easily displayed by just running the command without any arguments, like so:

host # ./rcscript.sh

Options -n -p and -f are required!

Usage: ./rcscript.sh [-h for this help screen]

Required switches:
[-n init script name] [-p name of program to control]
[-f controlled program's fully qualified name]

Optional switches:
[-i init directory] [-3 rc3.d directory] [-0 rc0.d directory
[-s start options for your program]
[-S stop options for your program]
[-k additional programs to kill on stop - space separated]
[-b common binary directory - defaults to /usr/bin]

Be sure to "double quote" any switch arguments with spaces!


Hope you enjoy the updates and this script helps you out in some way or fashion :)

Cheers,

Creative Commons License
rcscript.sh by Mike Golvach is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.
Based on a work at linuxshellaccount.blogspot.com.
Permissions beyond the scope of this license may be available at http://linuxshellaccount.blogspot.com.

#!/bin/sh
#
# Generic Init Script Creator
# 2009 - Mike Golvach - eggi@comcast.net
#
#Creative Commons License
rcscript.sh by Mike Golvach is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.
Based on a work at linuxshellaccount.blogspot.com.
Permissions beyond the scope of this license may be available at http://linuxshellaccount.blogspot.com.
#

trap 'rm -f ${init_dir}/${script_name} ${rc3_dir}/${script_name} ${rc0_dir}/${script_name} ${script_name}' 1 2 3 9 15

# Tips for a few command line arguments - setting an argument to zero will not be considered equivalent to not defining it
# a. set init_dir to 0 if you don't want any scripts and links setup - set rc3_dir, rc2_dir and/or init_dir to "0" to not create that link/script.
# b. If any of the init_dir, rc2_dir and/or rc3_dir variables are not set, they will default to the examples below.
# c. options that include 0 in the example do not need to be set and are entirely optional
#

# init_dir= /etc/init.d or 0
# rc3_dir= /etc/rc3.d or 0
# rc0_dir= /etc/rc0.d or 0
# script_name= myStartScript.sh
# program_name= testProgram
# fully_qualified_program_name= /usr/local/sbin/testProgram
# start_options= "start" or 0
# stop_options= "stop" or 0
# sure_kill= "space delimited list of extra programs to kill" or 0
# common_bin_directory= "place where common binaries are on your system" or defaults to /usr/bin
#

function usage()
{
echo
echo "Usage: $0 [-h for this help screen]"
echo
echo "Required switches:"
echo "[-n init script name] [-p name of program to control]"
echo "[-f controlled program's fully qualified name]"
echo
echo "Optional switches:"
echo "[-i init directory] [-3 rc3.d directory] [-0 rc0.d directory"
echo "[-s start options for your program]"
echo "[-S stop options for your program]"
echo "[-k additional programs to kill on stop - space separated]"
echo "[-b common binary directory - defaults to /usr/bin]"
echo
echo "Be sure to \"double quote\" any switch arguments with spaces!"
echo
exit 1
}

while getopts 0:3:b:f:hi:k:n:p:s:S: option
do
case $option in
'i')
if [[ "$OPT_ARG" == "0" ]]
then
init_dir=0
else
init_dir="$OPTARG"
fi
;;
'3')
if [[ "$OPT_ARG" == "0" ]]
then
rc3_dir=0
else
rc3_dir="$OPTARG"
fi
;;
'0')
if [[ "$OPT_ARG" == "0" ]]
then
rc0_dir=0
else
rc0_dir="$OPTARG"
fi
;;
'n')
script_name="$OPTARG"
;;
'p')
program_name="$OPTARG"
;;
'f')
fully_qualified_program_name="$OPTARG"
;;
's')
if [[ "$OPT_ARG" == "0" ]]
then
start_options=""
else
start_options="$OPTARG"
fi
;;
'S')
if [[ "$OPT_ARG" == "0" ]]
then
stop_options=""
else
stop_options="$OPTARG"
fi
;;
'k')
if [[ "$OPT_ARG" == "0" ]]
then
additional_kills=""
else
additional_kills="$OPTARG"
fi
;;
'b')
if [[ "$OPT_ARG" == "0" || -z "$OPT_ARG" ]]
then
common_bin_directory="/usr/bin"
else
common_bin_directory="$OPTARG"
fi
;;
'h')
usage
;;
*)
usage
;;
esac
done

if [[ -z $script_name || -z $program_name || -z $fully_qualified_program_name ]]
then
echo
echo "Options -n -p and -f are required!"
usage
fi

if [[ -z $common_bin_directory ]]
then
common_bin_directory="/usr/bin"
fi

if [[ -e $script_name ]]
then
rm $script_name
fi

cat << EOM >>$script_name

#!/bin/sh

#
# ${program_name} init script
# Usage: $script_name [start|stop|restart]
#

case \$1 in
'start')
echo
echo Starting ${program_name}....
echo
${fully_qualified_program_name} ${start_options} >/dev/null 2>&1 &
${program_name}_running=\`${common_bin_directory}/ps -ef|${common_bin_directory}/grep "${fully_qualified_program_name}"|${common_bin_directory}/grep -v grep|${common_bin_directory}/awk '{print \$2}'\`
if [ "\$${program_name}_running" == "" ]
then
echo "${program_name} start cannot be confirmed. Please check"
echo "system output and application logs for further detail"
else
echo "${program_name} started successfully"
fi
;;
'stop')
echo
echo Stopping ${program_name}....
echo
if [ "$stop_options" != " " ]
then
${fully_qualified_program_name} ${stop_options} >/dev/null 2>&1 &
fi
${program_name}_walking=\`${common_bin_directory}/ps -ef|${common_bin_directory}/grep "${fully_qualified_program_name}"|${common_bin_directory}/grep -v grep|${common_bin_directory}/awk '{print \$2}'\`
if [ "\$${program_name}_walking" == "" ]
then
echo "${program_name} does not appear to be running."
echo "Process not found. Not shut down."
else
counter=5
dead="alive"
echo "Shutting ${program_name} down."
echo "${fully_qualified_program_name} - pid ${program_name}_walking - stopping."
while [ \$counter -gt 0 ]
do
${program_name}_still_walking=\`${common_bin_directory}/ps -ef|${common_bin_directory}/grep "${fully_qualified_program_name}"|${common_bin_directory}/grep -v grep|${common_bin_directory}/awk '{print \$2}'\`
if [ "\$${program_name}_still_walking" != "" ]
then
echo "killing pid \$${program_name}_still_walking "
${common_bin_directory}/kill \$${program_name}_still_walking
counter=\`expr \$counter - 1\`
sleep 1
else
dead="dead"
echo "dead"
counter=0
fi
done
if [ \$dead = "alive" ]
then
echo "Could not kill process after 5 attempts."
echo "Process ${program_name}_walking still active."
${common_bin_directory}/ps -ef|${common_bin_directory}/grep "${fully_qualified_program_name}"|${common_bin_directory}/grep -v grep
fi
fi
EOM
if [[ $additional_kills && ! -z $additional_kills ]]
then
cat << EOM >>$script_name
for aks in `echo $additional_kills`
do
echo
echo Stopping \$aks....
echo
aks_walking=\`${common_bin_directory}/ps -ef|${common_bin_directory}/grep "\$aks"|${common_bin_directory}/grep -v grep|${common_bin_directory}/awk '{print \$2}'\`
if [ "\$aks_walking" == "" ]
then
echo "\$aks does not appear to be running."
echo "Process not found. Not shut down."
else
counter=5
dead="alive"
echo "Shutting \$aks down."
echo "\$aks - pid \$aks_walking - stopping."
while [ \$counter -gt 0 ]
do
aks_still_walking=\`${common_bin_directory}/ps -ef|${common_bin_directory}/grep "\$aks"|${common_bin_directory}/grep -v grep|${common_bin_directory}/awk '{print \$2}'\`
if [ "\$aks_still_walking" != "" ]
then
echo "killing pid \$aks_still_walking "
${common_bin_directory}/kill \$aks_still_walking
counter=\`expr \$counter - 1\`
sleep 1
else
dead="dead"
echo "dead"
counter=0
fi
done
if [ \$dead = "alive" ]
then
echo "Could not kill process after 5 attempts."
echo "Process \$aks_walking still active."
${common_bin_directory}/ps -ef|${common_bin_directory}/grep "\$aks"|${common_bin_directory}/grep -v grep
fi
fi
done
EOM
fi
cat << EOM >>$script_name
;;
'restart')
echo
echo ReStarting ${program_name}....
echo
\$0 stop
\$0 start
;;
*)
echo "Usage: \$0 [start|stop|restart]"
;;
esac
EOM

${common_bin_directory}/chmod 750 ${script_name};
${common_bin_directory}/cp ${script_name} ${init_dir}/${script_name}
${common_bin_directory}/ln -s ${init_dir}/${script_name} ${rc3_dir}/${script_name}
${common_bin_directory}/ln -s ${init_dir}/${script_name} ${rc0_dir}/${script_name}


, Mike


Banner for College Student-Oriented Sites (728 version 1)



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Tuesday, January 26, 2010

More Funny Linux Posters - Or, Part Two

I'm leaving this page up, but, as many of you have probably noticed, I've been too busy to write this blog for quite a while. I hope to continue writing again soon. I actually have been writing some fiction, but, for the most part, that doesn't fit the spirit of this blog ;) If you're interested, just look up "Golvach" on Amazon.com or check out this link (The first chapter should be available for free). We'll be talking to you soon. ...after I'm done going through the 40,000+ emails in my inbox ;)

Ahoy,

Another day spent raging against (or in some kind of opposition to) the machine has left me no time to write, if I want to get to know my kids before they grow up ;) I think, given the economy, I may have to break my streak and go to posting 3 or 4 times a week instead of every day (I can't afford to work contracts anymore and I'm not entirely comfortable quitting my full time job and rolling the dice in America's economy just yet ;) I think I'm going to be dropping a 500+ day-or-so streak (I'm too mentally goofed to even add now... yay ;)

Enjoy the rest of the posters. They certainly enjoy you ;)

Cheers,



Ubuntu
Oooobuntu
Please change your password. It smells awful!
Another fake book for idiots who like being called dummies
Alien Idol
God Bless Her




, Mike


Banner for College Student-Oriented Sites (728 version 1)



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Monday, June 29, 2009

Humorous Linux Posters - Part One

A cheerful, bright and sun-shiney Monday to you,

In our ongoing tradition of scouring the web for funny stuff (to make up for actually having to work, which takes away from blog-writing time ;), here's another collection of humor pieces. Posters, actually. The sentence before last was an attempt to sound highbrow while writing about low art. Not that posters are bad, in principal, but... Well, you be the judge :)

BTW, if the Linux Command Reference poster seems out of place, you can rest assured that it is. There's no joke to find in there. The reason we chose it was because of how very little it seems to actually cover. Pity the sysadmin who tries to get by on that amount of advice. It's got some good stuff in there, but it's not a safety-net by any means. Think of it as equivalent to MS Word's "Grammar Checker" to a non-English-speaking American, writing his new resumé. He can get rid of all those red and green underlines, but, in the end, his job application will be completely unreadable and insane. At best, he'll have a shot at landing a job in a special-needs environment ;)

Enjoy the posters, all pictures are copywrite of their respective creators and, as always, Cheers,



RedHat
Look, A Linux Poster!
Go Get 'Em
Gentoo
Fedora
Birds In Black



, Mike


Banner for College Student-Oriented Sites (728 version 1)



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Sunday, June 28, 2009

GloboChem: Hilarious Video From Mr. Show

Happy Sunday :)

SPECIAL NOTE FOR PARENTS: The video embedded in today's post contains effusive amounts of swearing in certain parts. Please don't watch with children present unless you've previewed and approved!

Today's post is way off-topic, but, as some of you may know, I'm a huge fan of Mr. Show and suffered from terrible depression for the entire period following its sudden cancellation and the release of the DVD box set of all 4 seasons. It wasn't all that long between the two, I'll admit, but it was really really hard on my fragile psyche ;) Check out this link for our post featuring another Mr. Show sketch called "The pre-taped call-in show." It's just as funny, if not funnier, and much more family-friendly :)

I hope you enjoy this video. I can't watch it without, at least, laughing on the inside. It runs a bit long, but, if you stay with it, you won't be disappointed.

Pit-Pat loves you ;)

Cheers,







, Mike


Banner for College Student-Oriented Sites (728 version 1)



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Saturday, June 27, 2009

Cool Computer Tricks - Interesting Optical Illusions!

Hey There,

Here's a little something that should be fun for a Saturday: Computer generated optical illusions! Probably everyone who reads this page has had a run in with some sort of optical illusion in their life (on purpose, of course ;) I'm just crossing the middle years of my own existence and I still love these things. And, despite what most everyone has told me to date, even staring at the LCD screen, optical illusions haven't diminished my eyesight. Of course, I'd be hard pressed to stare too long at my old Apple IIc. In fact, just turning that thing on begins to melt my flesh. It's probably a highly dangerous piece of equipment ;) I'll be giving it away soon (to a fellow old-computer aficionado) and (for some masochistic reason) I'll probably really miss it...

I found all of the illusions (and one "neat picture") posted here today over at coolopticalillusions.com. It's a great place to visit and has a huge variety of different illusions and other art and graphics that are just cool (as their site title suggests ;).

Below, I've posted pictures of the standard "spinning circles" illusion (although that's probably not the technical name for it), the Obama Illusion (which is eerily similar to the "Jesus" illusion - and the site has an animated version of it available), the disappearing confetti illusion" (which you should visit their site to check out, since they have three different versions of it which all work slightly differently) and a simple "cool picture" of a snowy grill that looks as though it's a human skull... who can explain why I choose the things I choose? ;)

Hope you enjoy these, and check out coolopticalillusions.com for some serious fun and equally serious eye-strain :)

Cheers,



What happened to Romper Room?

Obama Cures Cancer

Bye Bye

Grillin' Up Skull



, Mike


Banner for College Student-Oriented Sites (728 version 1)



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Friday, June 26, 2009

Warm computer accessories: The perfect gift for Dad!

Hey There,

Hopefully, regular readers will pardon this week's insanity as I've spent most of my free time in a fruitless struggle with Mail2Blogger. I'm going to give up on that until I have lots of time on my hands (and no pent-up aggression left... I should be something like an empty vessel by the time I take it on again ;)

Also, as part of this rambling preamble, I'd like to apologize to the many people who's emails I have yet to reply to (or even get around to reading). As my children grow up, and work continues to come my way, I'm finding less and less time to write decent posts, read emails, maintain my sanity, etc ;) I'm thinking that, soon, I'll probably cut my posting down to 3 or 4 days (pre-set) of the week. Believe it or not, writing fluff to fill those days when I don't have time to crank out any good stuff actually takes more out of me in the long run and then, when it comes time to put up something decent, the end-product is much worse than I'd prefer. Hopefully, some of the stuff I've put up in the meantime has been helpful and/or given you a good laugh (both works, too ;)

With that said, here's another fluff-piece ;) I found all of the pictures (except for the first one) at WarmMouse.info. The site is actually pretty interesting and has lots of useful information on combatting carpal tunnel syndrome. I must admit that it sounds like it's a very painful and annoying condition yet, strangely enough, I've never met anyone who suffers from it and (I've been typing since I was a kid) have yet to be cursed with it. I can't explain why I don't have it, since everything I use to get my work done is ergonomically-challenged (I'm typing this while bent over sideways from the side of the couch on my laptop that I can just barely reach on the ottoman a foot away ;) Perhaps it has to do with the way I always have my work-space set up. The picture below is a pretty accurate representation. It's just missing the keyboard :)

Yes, This is the Maxell commercial from way back when!



In any event, for those of you who don't already have sweaty clammy palms, check out the site above (pictures from it below). They have a computer accessory to warm virtually every computing appendage on your body (that you might reasonably be expected to use. If you end up with carpal tunnel from overindulgence in under-the-table behaviour, they can't help you there. Your best bet in that situation is to see your doctor and tell him you have Tennis Elbow ;)

With warm regards,

Click any of the pictures below and get ready for an edge-of-your-seat thrill-ride that will take you to places you never... okay, they'll just get slightly larger ;)







, Mike


Banner for College Student-Oriented Sites (728 version 1)



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Tuesday, June 23, 2009

Eclectic And Funny Linux Pictures - Last Day Of Vacation

Hey there,

The last day of vacation is here. Tomorrow (assuming everything has gone to plan) I'll be back in town to either be pleasantly surprised or utterly horrified. And, of course, I'm talking about the blog... Nothing to do with my home life or job ;)

Hope you enjoy the pictures and I can't wait to get back and write something soon. Hopefully, I'll remember how to after going through my backlogged emails (work and play)

Cheers,

NOTE: All pictures are copywrite of their original creators.



Too

many

pictures

not

enough

cutsie

comments




, Mike


Banner for College Student-Oriented Sites (728 version 1)



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Monday, June 22, 2009

Out To Lunch - More Funny Linux Pictures

Hola,

This blog's owner is still on vacation, but hopes to return shortly (and very soon ;)

Hopefully this post is actually making it online. The guy who writes this blog hasn't checked on me in a little while, and, being a simple chunk of text, I have no idea if I'm posting correctly or not... Here's hoping ;)

Enjoy the pictures and, dear author, please come back and take care of me soon!

Cheers,



a

b

c

d

e.  nice comments, huh?

f.  And you thought I'd give this one some effort...



, Mike


Banner for College Student-Oriented Sites (728 version 1)



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.