(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Kerio Reseller
Printer Friendly Version

Wrapper scripts


2006/12/05

I saw a news group post this morning that was trying to do something fairly complicated with "wget". Basically he had a list of servers that he wanted to get certain files from, but for one particular server, there was one file he did NOT want to get. He didn't say why, or why he couldn't just get it and deal with skipping or removing it from his machine later, but maybe it was exceptionally large or had other undesired side effects. It doesn't matter: the heart wants what the heart wants.

Now maybe there is some switch in wget that can do this: that's not my particular interest here. Here I want to discuss how you can use shell scripts to get what you want even though some other program doesn't want to play along.


Hate these ads?

For example, our "wget" issue. Let's look at it generically; given a file "servers" that contains:



server_one
server_two
server_three


And a file "files" containing:



file1
file2
file3
unwanted
file4


You can skip "unwanted" for server_two with a script like this:



 for i in `cat servers`
   do
   echo -n "$i "
   case $i in
      server_two) echo `cat files | sed '/unwanted/d'`;;
        *) echo `cat files`;;
    esac
    echo "  "
 done







When run, that produces:




server_one file1 file2 file3 unwanted file4


  
server_two file1 file2 file3 file4


  
server_three file1 file2 file3 unwanted file4





cartoon
Need eyes on the ground at your customer's site?
Installation and light training Boston and New England
Reliable and experienced, punctual and professional.

If we replace "echo" with "wget" and insert the appropriate flags, we have what we want.

Wrapping commands in shell scripts can solve difficult problems, but make sure you aren't ignoring capabilities of the command itself. For example at More reasons to love Unix/Linux, I show a shell wrapper that wants to find files NOT containing a certain pattern. That's a simple script:



grep -l "$1"  *.html >~/a
ls *.html > ~/b
diff ~/a ~/b | sort


But even more simple (assuming your "grep" supports this switch) is:



grep -h "$1"  *.html | sort -u


Often "old time" Unix folk will miss things like this because we have used "grep" and other commands for many, many years, but we haven't recently read the man pages. GNU versions of time honored Unix commands often have extended capabilities; make sure you check before you wrap.



Comments /Unixart/wrapper_scripts.html


Add your comments

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner





Views for this page
Today This Week This Month This Year  Overall
72415591 2,746

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

pavatar.jpg
More:
       - Shell
       - Linux
       - Unix
       - MacOSX
       - OSR5




Related Posts

How do I recursively grep through sub directories?

Xargs test question

grep and ps

Xargs test question

Xargs

Grep -d --recurse

How do I solve an "arglist too long"?

Grep awk example`

Grep in Depth


Unix/Linux Consultants

Your ad here - $24.00 yearly!

UBB Computer Services Support for Openserver, Unixware and Linux. Windows integration with Unix/Linux servers. Hardware, Backup and Networking issues. Located near Sacramento CA, we provide onsite support throughout Northern CA and Nationwide via remote access. We are a SCO Authorized Partner and a Microlite BackupEdge Certified Reseller.


http://www.vss3.com SCO/Caldera OpenServer, Unixware & Linux. Tarantella & Non-stop Clustering


http://echo3.net/ Unix/Linux Custom Applications, Web Hosting, C/C++ Programming Courses




Twitter
  • Jun 26 21:28
    Lost 5 cents at poker tonight. Hard to do with 10 and 20 cent betting..
  • Jun 23 07:01
    Hypermiling:







Coming Attractions

My Favorites

Change Congress

Related Posts