Free tech support / small logo


Shell Script Programming

Parsing "id" strings in a Shell Script?

Hello Dave. I need a Bash shell script that creates a directories with the group names automatically when user logs in to the system, in their home directory.

For example, user "sandy" might have the following set of groups from the 'id' command:

uid=10002(sandy) gid=119(rtkit) groups=119(rtkit),10001(admin),10003(pr007drdl)

and the directories "rtkit", "admin" and "pr007drdl" should then be created. How do I do it?

Question answered on January 19, 2012 at 08:49 AM ::

Copy and Paste from the Mac OS X Command Line?

I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes, I'm a tech writer. What I'm wondering is if there's any way to actually copy and past into the Mac system wide copy/paste buffer directly from the command line?

Question answered on January 3, 2012 at 08:26 AM :: Comments to date: 0

Script to test line lengths for Twitter compatibility?

I've been tasked with writing a series of tweets for a Black Friday marketing campaign and am finding it a bit tricky because I don't know how to easily check line length for a long series of lines. I'm on a Mac and can get around in Terminal. Is there some script you can share with me to check this, Dave?

Question answered on November 21, 2011 at 08:12 AM :: Comments to date: 1

Shell script to convert lowercase to title case?

As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that converts a sentence of all lowercase to title case. You know, from "this is a test case" to "This is a Test Case". Not every word, just the right ones. Doable?

Question answered on March 14, 2011 at 08:27 AM :: Comments to date: 0

Can I script renaming files based on an XML data map?

I have a folder full of files which are named with four digits and a file extension e.g. 0312.file and an XML-file describing the contents of these files. I am trying to do a shell scipt that will create folders and rename these files according to the xml, but I don't know how?

This is a template of what the xml looks like:

<section label="AA. category">
<children label="topic" source="AABB.file" />
</ section>

The script should represent the categories as folders containing the related topics, which should be represented as filenames.

Question answered on November 3, 2010 at 08:25 AM :: Comments to date: 0

Test for valid numbers in a Bash shell script?

In a different discussion on this site [see Redirecting input in a shell script] a visitor commented that "I was too busy trying to make sure the above post made sense that I forgot to ask for help. If you can, please post examples of how I can make the second argument a requirement and evaluate if it is a number. Thank you in advance!"

Question answered on October 25, 2010 at 07:35 AM :: Comments to date: 0

Can I sequentially rename files in Linux?

As part of some user interface testing I'm involved with on an Ubuntu Linux system, I find myself frequently having to rename groups of files in a sequential manner. That is, I'll have files like "output mm-dd-yyyy at hh:mm:ss" and need to rename them to "testrun-xx-file-yy". Is there any way to automate this so I don't have to go crazy typing?

Question answered on June 18, 2010 at 08:16 AM :: Comments to date: 3

Why is shell script programming so fun?

Dave, can you tell me, how come I enjoy shell programming more than other types of programming (Javascript, Java or C)?

Question answered on March 9, 2010 at 08:00 AM :: Comments to date: 2

How can I keep a compressed Linux archive up to date?

We have a situation where we need to keep a ZIP archive of some data files available on our Ubuntu Linux server so that our satellite offices can grab the information through slower data lines. Problem is, the underlying files change 2-3 times a day. What's a quick, efficient way to only rebuild the ZIP archive file on our Linux system if a file's changed, but leave it as-is if everything's stayed the same?

Question answered on August 29, 2009 at 08:32 AM :: Comments to date: 2

How do I find out what searches people did to end up on my Web site?

I've been trying to figure out whether there's a way that I can automate digging through the "referrals" on my site so I can see what searches people did to end up on one of my Web site pages. I'm running a Linux server and have Apache installed, so I get a huge log file with tons of info. But what I'd love is a simple script that will let me get email once a week with a sorted list of what searches people did to get to me. Doable?

Question answered on June 4, 2009 at 08:27 AM :: Comments to date: 7

How can I convert map addresses into latitude longitude?

I'm trying to write a shell script that will accept a street address and output the latitude and longitude of that address, for geocache purposes. How can I do that?

Question answered on April 18, 2009 at 09:15 AM :: Comments to date: 3

How can I bulk rename Apple iPhone screen captures?

As part of my work, I take tons of screen captures on our test Apple iPhone for documentation, but my boss wants me to use SEO friendly file names and it's a huge hassle to rename them one by one. Is there some sort of script I can use on my Mac to fix things?

Question answered on April 3, 2009 at 08:23 AM :: Comments to date: 0

How do I analyze word use in a document or book?

I've got a bet with my husband and you need to help us settle it. I was reading Jane Austen's "Pride and Prejudice" and he said "I bet you $20 that "pride" shows up more than "prejudice" in that book." I think he's wrong, but have no idea how to figure it out. Can you help?

Question answered on December 5, 2008 at 08:29 AM :: Comments to date: 8

How can I count letters in a text file?

Hey I want a Perl script that reads a file and sends me the number of occurrences of the alphabets in that file... Could you please help me?

Question answered on November 29, 2008 at 09:50 AM :: Comments to date: 0

How can my shell script test server status?

i am in big problem so please help on it. below i write the scripts, i don't know it is correct or not, but i want write the shell script for. In particular machine need to check all process are running or not, and we need result to display in the web page like server name = running, not only single server we have so many servers so, result like in the web page:

server1 = running
server2 = not running
server1 = running

like that so many server we have and one more thing is need show in web page with colors and fonts. please help on it!

Question answered on August 2, 2008 at 08:41 AM :: Comments to date: 4

How do I read prior lines in a text file?

I want to compare a line in a file with zero(0) and if its more than zero i want to print the prior two lines, can u please help me in solving out this... please

Question answered on July 15, 2008 at 08:07 AM :: Comments to date: 0

Can I automate craigslist searches?

I want to know if there's some way to automate searching the craigslist site with a shell script or similar so that I can keep an eye on it and know when certain rare auction items show up for sale?

Question answered on June 27, 2008 at 08:34 AM :: Comments to date: 6

Update to Wicked Cool Shell Script #62: define.sh

This is regarding script #62 (define a word): Looks like WordNet has changed their online version again and I tried the following replacement for the url=

http://wordnet.princeton.edu/perl/webwn?s=

But the script doesn't return anything but goes back to the prompt. I tried the url with a word in lynx and I got the source. Could you push me in a general direction?

Question answered on April 14, 2008 at 08:39 AM :: Comments to date: 2

How do I step through numeric values in a shell script?

Please, gimme a advice how to correctly use loop "for i in `seq 1 10`" for Mac OS X, echo $SHELL->/bin/bash, because when I write simple strip: for i in `seq 1 10`;do echo $i;done it outputs -bash: seq: command not found.

Question answered on December 31, 2007 at 08:00 AM :: Comments to date: 3

Can I send Twitter updates from the command line?

I'm becoming a big Twitter fan, but as a Linux user, I find it darn frustrating that most of the apps out there are for Mac and Windows users. I mean, I'm used to it, but is there at least some way to get to Twitter from the command line?

Question answered on December 28, 2007 at 08:01 AM :: Comments to date: 3

How do I create a custom stock market index?

My boss had a great suggestion for our local business web site: create a stock index like the S&P 500 that's just comprised of companies in our area. He said we should add it to our site but I honestly have no idea how to do that. Help!

Question answered on May 15, 2007 at 09:23 AM :: Comments to date: 10

How many Friday the 13ths are there in a given year?

I'm studying Unix, and i need help writing a script. The script requires that it outputs the number of months and years from January 2007 to December 2017 inclusive that have a Friday the thirteenth.

Question answered on April 28, 2007 at 01:26 PM :: Comments to date: 5

Bug in shell script using awk to read /etc/passwd?

In your book Wicked Cool Shell Scripts, on p. 115, Script #40 Reporting Disk Hogs, on the 8th line the second part of the line reads:

    awk -F: '$2 > 99 {print $1} ')

I am very new to shell scripting, so I am probably just not understanding how this line should be interpreted. In my Linux class, I have been learning that in the /etc/passwed file the 1st field is username, the 2nd field is password (x), and the third field is the UID, so wouldn't the $2 above really be $3 so that the script would be checking to see if the UID field, which is field 3 is greater that 99, not the password field,which is field 2? Please let me know, since this is confusing to me. Thanks for your help.

Question answered on March 26, 2007 at 12:39 PM :: Comments to date: 1

How do I turn a command line into a shell script?

I've been experimenting with mencoder to convert my AVI movies into a format that I can download onto my cellphone and finally found a site where they explain the various parameters needed for the mencoder program to get it to work. Problem is, they're a pain to type in each time. How do I turn an ugly command line invocation into a nice shell script?

Question answered on February 6, 2007 at 08:34 AM :: Comments to date: 2

How do I compare float / real numbers in a shell script?

Hi i am trying to comapre numbers for the biggest among double type of numbers. For example: 0.254, 0.255, 0.564, 0.984, 0.556, 0.6566, and 0.5666.

I'm using the following script code:

if [ $max -lt $i ]
if [ "$max -lt "$i" ]

But they all give the error message "integer expression expected". Help!

Question answered on January 19, 2007 at 08:16 AM :: Comments to date: 20

How can my shell script test to see if it's already running?

I have a script that does an ftp from a SCO UNIX server to windows server to get files from the windows server. The script is set in the cron to run every xx minutes. Sometimes the script will hang and leave a process running. This can bog down the UNIX server. I want to be able to do two things. 1. I want to make sure that the script doesn't hang - so it should terminate after xx minutes (the files are very small that it is getting). And 2. I want the script to test to make sure that it is not already running, before starting again. THANKS

Question answered on October 27, 2006 at 07:42 AM :: Comments to date: 5

How can I count executable binaries on my Linux box?

I've been looking at your script to count executable binaries in the book Wicked Cool Shell Scripts and I think that there's a problem in the script. Specifically, what happens if I have a directory in my PATH more than once?

Question answered on October 25, 2006 at 08:30 AM :: Comments to date: 1

Can I create an Apache image directory browser script?

I run a fairly busy Web site with a variety of different image directories. The problem is, Apache shows directories in a fairly rudimentary way which makes it quite difficult to find a specific image if I don't remember its name. Is there a better way with some sort of shell scripting?

Question answered on October 23, 2006 at 10:39 AM :: Comments to date: 3

How can I time portions of a Linux shell script?

Just picked up your book Wicked Cool Shell Scripts and already have one quick question: While working on the startup scripts, I would like to place log timers at certain portions of scripts. Is it possible to log point A at he beginning of a section, do the processing, log point B at the end of the section and then log B minus A so I know exactly how long a section took to process?

Question answered on September 13, 2006 at 05:06 AM :: Comments to date: 10

Do most music CDs have 12 tracks?

This might sound like some wild conspiracy theory, but I'm looking at my music collection and it sure seems like most of them have exactly 12 tracks, no more, no less. Is there some marketing reason this would be the case, or am I witness to some great conspiracy? :-)

Question answered on July 14, 2006 at 09:03 AM :: Comments to date: 5

Script to rename thousands of files and directories?

I need to rename thousands of files in MacOS, buried in subdirectories, changing " " to "_". I've found a ton of scripts using Google that purport to do this, but none of them actually work right. Can you please send me a script that does this? I also tried Automator, but it doesn't recurse into subdirectories.

Filenames may have multiple spaces (eg "Holidays/Christmas/Gifts & Stockings (A - G)/stocking.png"). Directory names may have spaces, too.

Question answered on April 28, 2006 at 09:03 AM :: Comments to date: 9

How do I strip leading zeroes for math in a shell script?

I have a file containing lines of data that are amounts padded with leading zeros, similar to the snip below.

  0000000004
  0000000016
  0000000012
  0000000008

Using a shell script, how can I add up a column of numbers contained in lines when BASH interprets the numbers as octal when I do in-line math?

Question answered on April 21, 2006 at 01:59 AM :: Comments to date: 19

How do I identify files changed during a specific month?

i am having difficulties writing a script to back up files which have need modified during the month specified in the option. The command is:
-b username yyyymm
so if i say 200504. i will have to back up all the files in that specific month to my home directory

Question answered on March 24, 2006 at 10:55 AM :: Comments to date: 1

How do I increment IP addresses in a shell script?

I need help with a shell script! I want to prompt someone to enter an IP address the automatically increment it and output the sequence of that address and its following addresses, but I don't know how to do that: when I try to increment a value like "10.10.10.27" it fails because it's not a number.

Question answered on January 27, 2006 at 09:16 AM :: Comments to date: 1

String comparisons don't work in shell scripts?

I'm a bit baffled. I'm trying to compare string variables in a shell script to figure out if one value is lexically less (that is, would appear earlier in the dictionary) than another, but it doesn't seem to work at all? Help!

Question answered on January 24, 2006 at 09:53 PM :: Comments to date: 2

How can I run an app if another app is running?

I need to run a Unix application if a different application is running, from within a shell script. How do I do this?

Question answered on January 9, 2006 at 11:16 AM :: Comments to date: 2

How can shell scripts check user ID?

We have several different shell scripts that we run on a daily basis. Sometimes one of the computer operators will execute the shell script as the wrong user (Root for example). This screws up the permissions and owenership on all of the files that the script just touched!!AAAARRGGGGGGHHH!

I am looking for a way, when the script fires, to see who is running it.

Question answered on December 8, 2005 at 07:25 AM :: Comments to date: 13

How do I delete all but one directory in Linux?

I have a series of boxes (over 1,000), that have the same directory that has been used over time as a dumping ground for various 'stuff', and now I need to have them cleaned up, save one sub-directory. What I need to know, is there a way to create a script that will allow any user to delete everything (hidden, directories, links, etc.) from a particular directory, except one sub-directory.

Question answered on December 7, 2005 at 04:29 PM :: Comments to date: 7

Automating SSH with a shell script

I am trying to write a shell script for automated ssh. vairable user and passwd have initialized correctly, but when I use the following it still prompting me for the password.

ssh -l $user cisdevapp1
$passwd
uptime
exit

I have also tried the following

ssh -l $user cisdevapp1 < $passwd
uptime
exit
EOF

and no luck. Please help?

Question answered on November 17, 2005 at 08:25 PM :: Comments to date: 14

How do I read lines of data in a shell script?

Dave, where can I find a bash script that can read data from a file; the information should be separated by tabs or commas for easy pickup, and can only be accesed by a row.

Question answered on November 17, 2005 at 06:13 AM :: Comments to date: 33

Date math in Linux shell script?

Within a Linux shell script to be used as a cron job, how do I calculate the current date, the current date - n days, and the current date + n days ?

This script is to be used to partition an oracle database, and automatically drop old partitions (n+1) and create a new partition (n+1).

Question answered on November 14, 2005 at 06:19 AM :: Comments to date: 36

Prompting users for passwords in a shell script?

How do you write a bash script for example, a user logins to the server's shell, then I want a bash script that will prompt him a password to verify he is a legit user not an intruder. The answer of the password will be located in a file (for example: /etc/verify). If the user not able to type the correct password 3 times the server will kill that connection and bans his IP address from the server.

Question answered on November 9, 2005 at 07:06 AM :: Comments to date: 11

Shell script to scrape /etc/passwd data?

I am working on a script where I would like to grab the usernames out of the passwd file and add a emaildomain then ftp it. For example I would like to pull the usernames for all users in /etc/passwd and add @domain.com the ftp it to ftp.domain.com . Can you help?

Question answered on November 8, 2005 at 05:40 AM :: Comments to date: 3

How do I rotate files in Unix?

On Solaris I have cron job which creates some log files and it puts it under a directory, this directory name is created based on system date for example directory name are like 08162005, 08172005 so on..

What I need is I want to do a rotation for these log directories every 14 days since these are directories with system dates, I am having little trouble getting this done,

Is there any way you can solve this for me??

Question answered on August 24, 2005 at 06:13 PM :: Comments to date: 6

How do I customize a script from "Wicked Cool Shell Scripts"?

Regarding script #41 (calculating available disk space), out of your book Wicked Cool Shell Scripts, I am unclear how I can have this script calculate the free space on one specific drive, namely /Volumes/Documents HD in my case.

I'd also love to know how I can automatically email the results of this same script, say every 24 hours. If you could kindly point me in the right direction, I'm sure I could figure out the rest!

Question answered on August 16, 2005 at 03:07 PM :: Comments to date: 1

Select range of users from /etc/password in a script?

I am working on a script where I would like to grab the usernames out of the passwd file for a defined range of UIDs. For example I would like to pull the usernames for all users in /etc/passwd that are in the range of 5000-5999. Can you help?

Question answered on August 14, 2005 at 05:06 PM :: Comments to date: 3

How do I re-redirect stdin in a Unix or Linux shell script?

Hi Dave. I'm trying to create a shell script in HP-UX Unix that looks like this:

while read usrname
 do
   lsh $usrname
 done < $file
and in lsh I added some error checks. If one occurs I ask the user to correct their input, but the code didn't work that way and it continues to read another line from file usrname. I don't know how to stop in while loop, to get input from the user. What's the trick?
Question answered on July 1, 2005 at 11:25 PM :: Comments to date: 4

Redirecting input in a unix shell script?

I have several SCO Unix script that read a parameter from user input or otherwise I put the param within my script, such as ftp scripts and so on. How can I read those parameters from a file instead?

Example: I write an ftp script that will connect to a remote location and bring files, right now I write the same script as many times as I have a remote location, but I'd rather substitute the open xxxx from a file. Also if it is an interactive script and the user need to send to more than one location then I need to be able to collect all the location numbers then read then into my script.

Question answered on June 15, 2005 at 01:40 PM :: Comments to date: 16

I hear that your shell scripting book won an award?

Dave, I heard that your book Wicked Cool Shell Scripts won some sort of award or the other? Do tell, what's the story with that?

Question answered on January 15, 2005 at 07:09 PM :: Comments to date: 0

How do I rename hundreds of files at once?

Dave, I'm in a bit of a pickle. Like you, I'm an author, and as I wrap up my latest book project, the development editor sent me a note saying that all the figures I've submitted, all 217 of them, are incorrectly named and need to be fixed. Augh! The naming scheme I'm using is FIGxxyy.TIF where xx is the chapter number and yy is the figure number. To make it a bit more complex, sometimes I use a three digit figure number and other times I use a two digit value. I need all the files to be called xxFIGyyy.TIF. How do I do that without going crazy?
Question answered on December 26, 2004 at 09:18 AM :: Comments to date: 9

Can I selectively remove Safari favicon icons?

I've been slowly adding all the nifty features to my new Web site and am going a bit crazy with Safari. I changed my favicon.ico favorites icon for my Web site, but Safari insists that it's not right, though when I view the site in Firefox, Camino or any other browser it's fine. How do I get Safari to be happy?
Question answered on December 22, 2004 at 02:24 PM :: Comments to date: 14

Can I extract all my Safari bookmarks with a shell script?

Alright, this is pretty geeky, but is there a way I can grab all my Mac OS X Safari bookmarks using a shell script so I can manipulate the data? I've peeked into the bookmarks file and yow, it's one hairy data file!
Question answered on December 20, 2004 at 11:47 AM :: Comments to date: 3

Can I use my Palm Desktop address book data in shell scripts?

Dave, I have a pile of addresses in my Palm Desktop address book on my Mac, but I'd really like to be able to use them from within some shell scripts, particularly to be able to build a quick reference of names and phone numbers. Is that even possible?
Question answered on December 17, 2004 at 11:00 AM :: Comments to date: 0

Does -prune work like -maxdepth in Unix "find" on AIX?

Dave, I purchased your Wicked Cool Shell Scripts book a month or so ago (great book), and have used it to "learn by example" in writing some shell scripts, as I've a long way to go in this area.

I need to rotate logs on an IBM AIX 5.1 Unix box, and tried using your script #55, rotatelogs for this but it didn't work, as -maxdepth is not supported in AIX's find command. So, I commented it out, and it worked, but also rotated everything in the subdirectories as well (no problem...backed up directory first, then restored). I am trying to get it to work using -prune which my search in Google found to be a good fix for the lack of maxdepth, but it's not doing what I want. Help!

Question answered on December 17, 2004 at 05:22 AM :: Comments to date: 5

What's acceptable syntax in Unix and Linux sh scripts?

Dave, I ran across your sites and Wicked Cool Shell Scripts book while trying to convince myself that `sleep 0` is a valid and relatively portable command to use freely in my unix shell scripts.

I looked at a few of the Bourne shell scripts and they seem to use constructs like $( ... ) and $(( ... )) which are not standard Bourne shell (to my understanding). So I actually have three questions, rather than just one:

  1. In what flavor of /bin/sh are those scripts written?
  2. Can you suggest any references regarding writing portable (Bourne) shell scripts?
  3. I would love to find an equivalent reference for what unix utilities *and options* to use for increasing script portability. Any suggestions?
Question answered on December 6, 2004 at 07:08 PM :: Comments to date: 1

Can I keep track of my Amazon book rank with a script?

Dave, do you happen to have a script that will pull Amazon.com hourly sales rank data for 1 - N ASINs and save into either a CSV file or a database?
Question answered on November 30, 2004 at 05:02 AM :: Comments to date: 2

How do I write a full-screen bash shell script?

Dear Dave: I am trying to write a full-screen utility that displays the permissions of a directory and all the directories in the directory's path. It should also show other information about the directories, as the cursor is moved up and down the list of directory names. Can you offer me some pointers to get me started?
Question answered on November 27, 2004 at 04:30 AM :: Comments to date: 1

Can I list my iTunes Library by number of albums?

I've spent a lot of time poking around with my extensive iTunes database and had lots of fun figuring out different ways to address my needs with a fully digitized music collection. When a reader asked whether there was a way to just list those artists in her iTunes collection for whom she had more than one album, I thought "ah, this sounds up my alley", and so it is.
Question answered on November 16, 2004 at 12:06 AM :: Comments to date: 11

Can I track an RSS feed with a shell script?

More than once, readers have written to me, asking if it was possible to track an RSS feed from a Weblog or news site with a shell script. Sounds kinda wacky, but in fact, it's a very good use of a shell script, as the following rather extensive entry -- including source code! -- demonstrates. If you're a bit confused by the following, you might want to consider picking up a copy of my best-selling Wicked Cool Shell Scripts.
Question answered on November 15, 2004 at 03:38 PM :: Comments to date: 6

How do I create a group-based disk usage script?

A reader writes:
"I've been reading your book Teach Yourself Unix in 24 Hours and learning a lot, but I'm stuck on a disk usage problem. Suppose there are 5 people (A, B, C, D, E) in our group and they share the same directory called "group." The total capacity of this directory is 100 GB. I'm looking for a program/command/script that can be run to generate the following space usage update:
 
    A    5         5%
    B   10        10%
    C   20        20%
    D   40        40%
    E    5         5%
 total  80        80%
  
   free space     20%
This is an interesting question, so let's dig into it and see what we can figure out...
Question answered on November 4, 2004 at 06:20 AM :: Comments to date: 6

How do I create a shell script on a Macintosh?

A reader writes:
I've started to go through your shell script book Wicked Cool Shell Scripts but there is still something I'm unclear on. I'm showing my ignorance here, but how exactly do you save a shell script so you can use it later?"
Question answered on October 7, 2004 at 10:05 PM :: Comments to date: 20

Tweaking FTP scripts to fine-tune their behavior

A reader writes:
I have your Wicked Cool book and love it. I am new at scripting and it is helping a ton. Question. I need a script to use the timestamp feature (ingenious by the way) of Script #83 but "get" the files from a remote server like Script #82. Do you have one modified in such a way?
Question answered on September 8, 2004 at 11:02 PM :: Comments to date: 0

Where can I get free tips about Linux shell script programming?

It's not uncommon for me to receive email from people asking for information that's covered in one or more of my books, and this morning I received a message asking about good places to go online to learn more about shell script programming. My answer, of course, is to buy a copy of my best selling book Wicked Cool Shell Scripts, but if that's not in your budget, there's another possibility to explore.
Question answered on September 2, 2004 at 01:17 PM :: Comments to date: 4

Extracting the correct column with "ps" and "awk"

A reader writes:
Every *nix implementation is different. But I'm seeing some some shared behavior between HPUX and Solaris with script #52 Killing Processes by Name. The problem is that the script is trying to kill the "tty" name, instead of the pid.

Wish I understood the following line better so I could make it grab the right columns. :-\

pids=$(ps cu -U $user | awk "/ $1$/ { print \$2 }")

Question answered on August 16, 2004 at 04:50 PM :: Comments to date: 4

Extracting Directory Names within a Shell Script

A reader writes:
First, thanks for writing Wicked Cool Shell Scripts. I've found them quite useful and I've learned many things from those scripts. I just have a question and I was wondering if you could point me in the right direction.

I'm trying to write a shell script that will pull the top-level directories out of a list of file paths, example:

list of files:
/usr/local/test
/usr/bin/test
/opt/Tivoli/dat
/opt/lib/test
/tmp/files/test
/tmp/local/test

Output after script:
/usr
/opt
/tmp

Question answered on August 11, 2004 at 11:21 PM :: Comments to date: 3

Another approach to working with "awk"

A reader writes in with the following note:
I've just picked up your book Wicked Cool Shell Scripts, and there are a lot of nifty things in it. I too have accumulated a lot of things generally in small scripts or more frequently in bourne/bash functions. I was particularly tickled to see a lot of very similar code, one such that jumped out at me was your gmk function in one script (I called mine kmg).

Would you be interested in some constructive criticism?

In script #52 Killing Processes by Name, I think that instead of:
  awk "/ $1$/{ print \$2 }"
you might consider using
  awk "$NF=="$1" { print \$2 }"

That way, you're not dependent on whitespace.

Question answered on August 6, 2004 at 11:46 PM :: Comments to date: 0

Permission to reuse the Wicked Cool scripts

I have received a number of queries from people in the Unix/Linux community asking for the details of ownership and copyright for the scripts included in my best-selling Wicked Cool Shell Scripts. When I first started programming and distributing my works online (in the early 1980's) no-one really worried about any of that and if the original author's name stayed intact, we'd think that was a wonderful thing.
Question answered on July 15, 2004 at 07:00 AM :: Comments to date: 0

How do I do just incremental backups?

A reader writes:
"My question concerns backup.sh (script #56 in the book Wicked Cool Shell Scripts). I am a little confused how to set up my directory list file INITIALLY to use for the backup script to work. Do you have to do a -f (full backup) first, then I'm free to incrementally backup as desired? Even then I'm only interested in backing some key directories not my whole home space...."
Question answered on July 15, 2004 at 06:36 AM :: Comments to date: 0

Getting the "adduser" script to work on Linux

A reader writes:
" Hi, I'm a very beginner at shell scripting and unix/linux. I have your book (Wicked Cool Shell Scripts) and it is really great. So far I've done two or three, Inpath is the one i use most. I'm going make a user for an ftp account so my friends can upload/download songs and other files. I decided to use your adduser script for the job but when i run the script i get an erorr like - /etc/passwd : permission denied. How do i give the script permission to write to /etc/passwd? Sorry if this is an obvious question but i couldn't find an answer. I used chmod 755 and ran it as root. By the way, i really like the site and book cover, i wish all linux/programming manuals had really cool covers."
Question answered on June 7, 2004 at 10:57 AM :: Comments to date: 4

Accuweather changed, and now the 'weather' script is broken!

A reader writes in to report that Accuweather has changed their Web page layout and the shell script from Wicked Cool Shell Scripts that returns the weather forecast (script #63, weather.sh), is broken.
Question answered on May 26, 2004 at 07:16 PM :: Comments to date: 2

Nifty shell script of the day: calculating standard deviation

If you find yourself working on the command line and need to whip out a quick statistical analysis or two, you'll be glad to know that Wicked Cool Shell Scripts fan Josh Kotecha has sent in a very nice little shell script that does just that using the scriptbc script included in the book.
Question answered on May 7, 2004 at 05:36 PM :: Comments to date: 0

Sneaky ls flags and bestcompress

Another hiccup in a script included in Wicked Cool Shell Scripts, one that's a subtle problem because it sometimes occurs because of a user-set LS_OPTIONS flag. Script #37, bestcompress, has the following sequence:
smallest="$(ls -l "$name" $Zout $gzout $bzout | \
awk '{print $5"="NR}' | sort -n | cut -d= -f2 | head -1)"
Question answered on April 25, 2004 at 11:36 PM :: Comments to date: 0

Permission checks in shell script

A reader of my new book Wicked Cool Shell Scripts pointed out that the capability of testing a file permission with find using the '+' notation is GNU-specific.
Question answered on April 25, 2004 at 11:18 PM :: Comments to date: 2

Can you prevent people from linking to the media on your Web site?

A friend writes:
I'm finding that some number of people are hosting my Janet Jackson "movie" by simply linking it in from their sites, meaning *I* get to pay for the bandwidth. Is there some way to prevent this?
Question answered on February 23, 2004 at 10:31 PM :: Comments to date: 3

Fixing Mac OS X's "periodic" command

I've been discussing the key tasks that a Mac OS X user has to run to ensure that their system stays healthy and in tip-top shape, and one set that we've all agreed upon are the daily, weekly and monthly cron jobs. You can figure out when they're run with a simple grep command.
Question answered on February 13, 2004 at 11:37 AM :: Comments to date: 5






Search
Find just the answers you seek from among our 3000+ articles by using our Lijit search engine.

Recent Entries on Ask Dave Taylor!

Help!
Need Help? Ask Dave Taylor!


Subscribe to
Ask Dave Taylor!

RDF XML
Add to My Yahoo!


Updates via Email
sent twice monthly



Apple iPad Help
Articles and Reviews
Auctions and Online Shopping
Blogs and RSS Feeds
Building Web Site Traffic
Business and Management
CGI Scripts and Web Site Programming
Computer and Internet Basics
d) None of the Above
Facebook Help
Google Plus Help
HTML and CSS
Industry News and Trade Shows
iPhone and Cell Phone Help
iPod, Sony PSP and MP3 Player Help
Mac OS X Help
Pay Per Click (PPC) Advertising
Search Engine Optimization (SEO)
Shell Script Programming
Tech Support Video Help
The Writing Business
Twitter, LinkedIn and Social Network Help
Unix and Linux Help
Video Game Tips and Help
Windows PC Help
WordPress Help

Archives by Category
Apple iPad Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Articles and Reviews
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Auctions and Online Shopping
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Blogs and RSS Feeds
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Building Web Site Traffic
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Business and Management
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


CGI Scripts and Web Site Programming
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Computer and Internet Basics
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


d) None of the Above
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Facebook Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Google Plus Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


HTML and CSS
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Industry News and Trade Shows
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


iPhone and Cell Phone Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


iPod, Sony PSP and MP3 Player Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Mac OS X Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Pay Per Click (PPC) Advertising
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Search Engine Optimization (SEO)
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Shell Script Programming
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Tech Support Video Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


The Writing Business
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Twitter, LinkedIn and Social Network Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Unix and Linux Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Video Game Tips and Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


Windows PC Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?


WordPress Help
Parsing "id" strings in a Shell Script?
Copy and Paste from the Mac OS X Command Line?
Script to test line lengths for Twitter compatibility?



sitemap   --   link to us!
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.