APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds RSS Feeds









Scripting



awk You need to know what awk is, and should at least be able to read a script that uses it, but I'd suggest that you use Perl whenever otherwise tempted to use this. The man page (nowadays it is probably gnu awk or "gawk" that you actually have) probably has some examples at the end of it.


Title Date Comments
Learning Spanish with a little help from Perl   2013 04  2013/04/16 TonyLawrence
- A little Perl script helps me refresh my Spanish knowledge. -
Early reminders for first Monday of month events   2012 10 
- I kept forgetting to send our club meeting notices to the newsletter. Google Calendar couldn't help me, so I wrote this script. -
Debugging a Mountain Lion slowdown   2012 10  2013/05/20 TonyLawrence
- I've had some performance issues since upgrading to Mountain Lion and have written some code to try to catch the problem as it happens. -
Here files (shell scripting)   2012 10  2012/10/09 TonyLawrence
- Once again, I've been bitten by not having read the manual recently. This bite really annoyed me. -
No clobber scp - scp without overwriting   2012 10  2012/10/07 TonyLawrence
- Although you usually want scp to update files, there are times when you definitely do not. I wrote this script to avoid overwriting existing files. -
Transferring Linux or Mac Perl scripts to Windows Cygwin   2012 10  2012/10/14 TonyLawrence
- There's usually some rewriting necessary when moving Linux or Mac Perl scripts to Windows. Here are some of the things to watch out for. -
Sending Kerio Calendar Event Reminders by Email   2012 09  2012/09/16 TonyLawrence
- This Perl script will loop through Connect Calendar events and send email reminders. -
Watching your Kerio Connect Mail Log   2012 09 
- This Perl script will check your Kerio mail log for potential problems and warn you if any are found. -
Keep a watchful eye on email delivery problems with this script   2012 09  2012/09/07 TonyLawrence
- Use this Perl script to keep a closer eye on email delivery problems. Notify yourself and your users of developing problems. -
Notifying service techs with Kerio Connect   2012 08  2012/09/05 NickBarron
- Scripting an 'on call' sms notification to service techs from a Kerio Connect public folder. -
Kerio Connect Administration API - setting user quotas   2012 04 
- The Kerio Administration API can help automate tasks that would otherwise be time consuming and perhaps error prone. Learn how to set user's quoatas with this simple example. -
Capture and report (Bash Scripting)   2011 11 
- You've been asked to copy some jpg files to a USB disk overnight. That's easy enough - a cron job and a simple 'cp -a' will do that. But there is so much that could go wrong, isn't there? There might not be any files to copy or there might not be room on the USB disk. Somebody might have changed permissions on files or directories alreasdy in place, preventing overwrite with updated images. -
 
 
Kerio Connect Mailserver
 
 
Auto Edge archive removal script   2011 09 
- The way I wanted Edge to work, was just like the days when we backed up to Tape. We would pull Master backups each night, label the tapes M-F, and take a SAT tape off-site for an extra layer of protection. When Monday rolled around, the new backup would replace the old Monday backup, rinse, lather, repeat. This changed when we upgraded to Edge 3.x, and started using the NAS. Once we had multiple servers with multiple jobs backing up to the same resource, and not having enough free space on the NAS because backups were piling up, I had to resort to manually deleting things (through edgemenu) on the NAS to free up space. This got old rather quickly, as I had to look down the long list of backup jobs, and determine which ones could be deleted. If I missed one day, the NAS would fill up, and backups would fail. -
Higher resolution timers in the shell   2011 07 
- In the olden days, we'd pick up the current time from 'date' and store that. Then, after suspect part of the script, we'd run it again and calculate the elapsed time. Simple enough, but 'date' limited us to whole seconds. We had nothing in the shell that was tighter. -
Perl Date::Manip for date validation   2011 05 
- Validating dates can be tricky, but Date::Manip makes it easy (at the cost of a little speed). -
KCMENU (Kevin Clark's menu generator) in Perl   2011 04 
- Translate old kcmenu files to Perl scripts - a simple Perl based menu script. -
Is sed dead?   2011 04 
- If you learn how to use sed, you get a bonus: the same editing commands can be used in ed and vi. -
The lowly ls command   2011 04  2011/04/20 TonyLawrence
- ls might have more flags than any other Unix command and operating system variance is wide. -
Finding Yesterday's Date   2011 04  2012/09/11 TonyLawrence
- How to find yesterday's date on Linux, Mac and any other Unix. -
Using unblock and block with dd to add linefeeds and whitespace padding -->Re need file manipulation command   1997-2004 
- Using 'dd' to convert fixed length records to line feed terminated text or to pad ascii text with white space to creae fixed length records. -
exported functions shell scripting -->Re SCO shellscripts   1997-2004 
- Most shells support "exported functions". Understanding how to make functions available to other scripts can be confusing. -
Getopt and getopts   2003 09  2012/12/19 TonyLawrence
- Both "getopt" and getopts are tools to use for processing and validating shell script arguments. They are similar, but not identical. -
Perl Net::FTP   2003 09  2013/03/13 armin
- Before the wide spread availability of Perl, I would script ftp transfers with .netrc, ksh scripts and other clumsy ways. None of those methods are fun, flexible or easy. On the other hand, Perl's Net::FTP module is all of that. -
Bash in-process regular expressions   2005 09  2010/09/27 JonathanCross
- Bash acquired in-process regular expressions in version 3.0, but I never noticed, probably because most of the machines I'm using are Bash 2.05b. -
uname version -->Re UNIX version check command   1997-2004 
- Usually some variant of uname, often 'uname -a', but all sorts of other possibilies; t d epends on the Unix and in some cases even the specific version. -
Take Control of the Mac Command Line with Terminal   2009 05 
- Old-timers like me couldn't avoid being exposed to command line interfaces - that's all we had when we started Younger people and people who simply started using computers a bit later weren't necessarily exposed to any command line. Any computer they ever used had a graphical user interface and while it still may have had a command line available, there was seldom any incentive to use it. That apparent lack of any compelling reason remains true, but in fact understanding the command line can give you much more control over your computer and allow you to accomplish some tasks much more quickly and easily. -
Continuation Lines   2006 06  2010/05/27 anonymous
- There's been a long standing Unix convention of breaking long lines with a "\" to make them easier to read. You'd almost always see this in files like /etc/printcap, but there are plenty of other places where this convention is used. -
Using color in shell scripts (Linux, Mac OS X)   2009 11  2010/01/03 BigDumbDInosaur
- Color is tricky. Displays can be bad at it, people can be color blind... using colors can make text hard to read - I don't like using color in scripts. -
Bash shell $PIPESTATUS   2004 06  2011/04/04 TonyLawrence
- PIPESTATUS array holds the exit status of your last foreground pipeline commands. -
using bash select   2005 09 
- The description of select in the bash man page is enough to give anyone a headache: -
Bash typecasting   2006 08 
- Bash has typecasts - but only sort of and your scripts can easily break because of it -
Using System V interface scripts with CUPS printing   2009 12  2012/11/05 TonyLawrence
- But what if I wanted to add an automatic form feed to the end of that, or do some other special processing? -
Awk vs. Perl   2009 11  2012/08/15 TonyLawrence
- Sure, I used to use awk. When I used it, you weren't likely to find Perl onmost Unix systems, so for a lot of text mangling, awk was at least easier than writing in C or anything else. It did the job, and you'd get used to its quirks. -
zip vs. gzip, compress, pack   1997-2004 
- The algorithm used by `gzip` is one of the ones used by `zip`. `zip` supports several algorithms and tries to choose which one will produce the smallest output (actually the Unix port of `zip` just uses one algorithm, called "deflate"). -
trapping error in bash script 'trap error ERR'   1997-2004 
- If a sigspec is ERR, the command arg is executed whenever a simple command has a non-zero exit status. The ERR trap is not executed if the failed command is part of an until or while loop, part of an if statement, part of a && or || list, or if the command's return value is being inverted via !. -
extglob (extended pattern matching bash)   2005 05 
- 2005/05/25 extglob (extended pattern matching bash) -
shell script read password without echo -->Re Readinginput without echo   1997-2004  2013/02/14 anonymous
- shell script read password without echo -->Re: Readinginput without echo -
User Friendly Date Script   2001 06 
- A more user-friendly command line front end to changing the date and time on Unix and Linux. -
Using the Korn Shell   1997 
- A.P. Lawrence, Linux/Unix Consultant-Korn ShellBasics -
Perl directory listing   1997-2004 
- Learning Perl basics to produce 'pretty' directory listing with 'File::Find'.: A "pretty" or custom directory listing is a good place to start developing your scripting skills if you want to. There certainly are utilities that do pretty listings, but the advantage of rolling your own is that you can do EXACTLY what you want and gain some useful skills while you are at it. -
Basic Scripting   2001 02 
- Scripting at its simplest is telling the computer what you want it to do by putting the commands you want to use into a file and running that file instead of typing the commands. -
excluding files from rsync --exclude   1997-2004 
- Trying to exclude files from rsync can be very confusing. Testing with local files or small data sets can help. There are some gotchas to watch out for, though. -
case conversion in bash script??   2006 08 
- Now I want to convert the content of VAR ($VAR) to lowercase. How can I do in bash. -
How and where to start writing first Shell Script in UNIX Part 2   2004 08 
- How and where to start writing first ShellScript in UNIX -
What does a leading colon (:) mean in a script?   2010 03 
- Bash and sh both use colons (":") in more than one context. You'll see it used as a separator ($PATH, for example), as a modifier (${n:="foo"}) and as a null operator ("while :"). -
A Y2k problem solved with Expect   1999 05 
- This is an old article about using Expect to solve a Y2K issue and is only left here for historical purposes. -
Using sh -c with find   2007 01 
- Using sh -c imbedded in find script. I'm sure everyone reading here has used "-exec" with "find"; for example: -
Shell vs. Applescript - getting input   2005 12 
- Of course there are things easily done with Applescript that aren't so easy with a shell script. However, the opposite is also true. Too often I see people writing complicated (and slow) Applescript for things that the shell can do very easily. -
Improving Leopard's QuickLook   2007 12  2010/12/20 Smokey
- Making Quicklook show me text files even though it doesn't want to. Other ways to improve Apple Quicklook -
telnet expect tutorial -->Re Passing command to Telnetwith a text file   1997-2004 
- telnet expect tutorial -->Re: Passing command to Telnetwith a text file -
 
 
Kerio Control Firewall
 
 
Bash looping   2005 06  2011/08/08 TonyLawrence
- There are so many different ways to create bash loops. Let's just look at a few. After the first, I'll only list the initial line: -
Mac OS X get ip address in script   1997-2004 
- Mac OS X get ip address in script to clipboard (various methods) -
redirect error messages to file -->Re cc source.c > tmp   2001 11 
- The same way one redirects stderr from any program: prog args 2>/tmp/error. If you want both stderr and stdout to go to the same place, prog args >/tmp/errs 2>&1 -
ERR trap (ksh) -->Re control errors in scripts   1997-2004 
- Note that bash has this same functionality. Search for "ERR" in "man bash" and also note "set -e" and "set -E". -
Death of the command line   2006 07 
- Is command line use dying? It's hard for me to imagine using an OS without a strong command line. Even Microsoft has recognized the with their Monad Shell. -
Learning the Bash   2000 03 
- But even beyond that, I liked this book as a general shell programming text. I liked the careful attention to details; the noting of the little quirks and gotcha's that some other authors might pass over. -
How and where to start writing first UNIX Shell Script   2004 08 
- The article doesn't cover the shell scripting it only gives a brief idea about what is UNIX shell and how and where to start writing first shell script. I shall cover variable, expression, control structures, function, file handling, awk programming, debugging one-by-one in my subsequent articles on the UNIX shell scripting. -
2>&1   2003 12 
- Shell redirection, and the '2>&1' is probably the most common form. More interesting is the case of a shell script where you want to capture stderr but let any "ok" output go to the screen. -
Bash 3.00 brace expansion   2005 10  2010/11/02 TonyLawrence
- With Bash 3.0, we now have brace expansion for lists. Prior to this, we sometimes used "seq", which could result in such awful things as: -


More Scripting articles

pavatar.jpg
book graphic












Have you tried our Tests?