unix scripting

Talk about pretty much anything here, but DO NOT USE FOR SUPPORT.

Moderator: Supporters

Locked
droolin
Posts: 42
Joined: Sat Dec 04, 2004 7:27 pm
Location: USA - Ohio
Contact:

unix scripting

Post by droolin »

I am currently writting a bunch of .sh scripts to automate alot of the crap that I normaly did on the various servers that I work on. I am useing .sh scripts because basicatly that works on all flavors of Unix.
Examples of scripts that I am looking to do or am doing.
Automaticaly backup the servers to remote site cause the admins wont do it.
Parse some logs for various information from each server.
And because I have a unix box set up at home, basicatly everything that is becomeing repetative that I'm getting sick of doing. Truthfully, I want to write a good backup script for my home machine that is specific to my needs.

So, my question is this. Can someone direct me to a good forum on unix shell scripting? And also the more tutorials I have for reference, the better. I have already written the automated ftp script. The logging, I know ill be useing grep and probably awk for. Maybe sed, but.... Errrr, I havent decided what I want to do yet with that issue. But, im looking for more area's that I can use for reference material and examples.
I kind of started the shell scripting to make life easier for myself, and and am enjoying the hell out of myself cause things are working out just how I wanted. So, as I said. Im looking for as many reference's as I can find on the subject. And yes, I buy reference books. So sugestions on reference books would be most appriceated also.
Lol, look at it this way. Most shell scripting requires working with regular expresions. This will give me a chance to get to know them better and more familuar with them. And I won't have to ask stupid questions here when I am setting spam filters.

Thank you in advance for any help you can provide.
Hornyness is a perpetual thang. The hornier you are, the hornier your going to be.
Shelluser
Posts: 38
Joined: Tue Feb 01, 2005 8:30 pm
Location: The Netherlands
Contact:

Re: unix scripting

Post by Shelluser »

droolin wrote:Can someone direct me to a good forum on unix shell scripting?
That is a rather difficult question because Unix knows a lot of different shells and some of them really are not compatible with each other. For example take a look at the Bash shell and the C Shell...

Anyway, I suppose you want to use Bash since that is commonly being used on Linux, and a link I find very helpfull is the Advanced bash scripting guide
With kind regards, Peter

NekoNet IRC
www.neko-net.org / [url=irc://irc.neko-net.org:6667]irc.neko-net.org[/url]
TigerDragon
Posts: 10
Joined: Mon Mar 28, 2005 2:50 pm

Post by TigerDragon »

You might consider using perl instead of sh. While it's true that sh will likely be on the system, nomatter what UNIX it is, the same can be said for perl. Perl is installed by default on almost every unix I can think of... solaris, linux, *bsd, hpux, tru64, aix. The only system I've used that it might not be on is Irix.

If you are adamant about using sh instead, it doesn't hurt to use the bash tutorials. You will likely find more tutorials on the more improved shells such as bash and ksh than vanilla sh. Unless you use some of the more esoteric shell features in your scripts, your scripts will run in sh, even if you learned them from a bash tutorial. Your best bet if you insist on doing sh is to simply use trial and error. Write scripts as you would according to the bash tutorials for instance, but then test it with sh. If it doesn't break, simply replace the bang line. If it does, try to determine why it did, and find a work around.

Just some suggestions.
codemastr
Former UnrealIRCd head coder
Posts: 811
Joined: Sat Mar 06, 2004 8:47 pm
Location: United States
Contact:

Post by codemastr »

TigerDragon wrote:You might consider using perl instead of sh. While it's true that sh will likely be on the system, nomatter what UNIX it is, the same can be said for perl. Perl is installed by default on almost every unix I can think of... solaris, linux, *bsd, hpux, tru64, aix. The only system I've used that it might not be on is Irix.
That is true, however there is still a problem. Sh is always in /bin/sh. Perl varies. I've seen /bin/perl, /bin/local/perl, /local/bin/perl /bin/perl5/perl and various other locations. That means the user needs to edit the script to ensure the path is correct for his/her system.
Your best bet if you insist on doing sh is to simply use trial and error. Write scripts as you would according to the bash tutorials for instance, but then test it with sh.

That doesn't work. On some systems, /bin/sh is really bash. So you might be testing with bash, then switching to another copy of bash, then assuming it works on sh when really you're still trying bash.
-- codemastr
TigerDragon
Posts: 10
Joined: Mon Mar 28, 2005 2:50 pm

Post by TigerDragon »

1) It's not that hard to change the bang line to point to the actual location of perl before uploading it.

2) It's also not hard to look to see if the /bin/sh on your system is actually /bin/bash. If you do an ls -l /bin/sh and it shows it is a symlink to bash, it's bash. If it's not a sym link, then do an ls -l on your bash executable and if the inode numbers are the same it's a hard link instead and is still bash. If they are different it's not bash.

For the trouble, perl is a better bet because the only change needed is the bang line.
AngryWolf
Posts: 554
Joined: Sat Mar 06, 2004 10:53 am
Location: Hungary
Contact:

Post by AngryWolf »

If you by any chance choose Perl, my suggestion is using the following as the first line:

Code: Select all

#!/usr/bin/env perl
Details:
Locked