NetAdminTools.com
 
SignalQ Sites:
NetAdminTools - Coprolite - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - FixRambler
Categories:
GNU/Linux | Homebrew designs | Perl | Ruby | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | ERP | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | GNU/Linux Reference OS Build | MCJ How-to | Keywords | RSS



Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Ruby
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·ERP
·REALbasic
·All Categories


Stupid Bash Tricks: Simple Loop With Timestamp
Topic:GNU/Linux   Date: 2003-03-17
Printer Friendly: Print

spacerspacer
<<  <   >  >>

Subject

We ran into an interesting situation where we needed to know two things: whether or not a particular server was down, and when, exactly, it went down. We had requested some service be done on the server, and had a shell open via ssh. A simple solution that did the trick, and illustrates some stupid BASH tricks, is this script:

u-1@srv-1 u-1 $ until [ 6 -eq 9 ]
> do
> echo $(date)
> sleep 1
> done
Mon Mar 17 14:01:13 PST 2003
Mon Mar 17 14:01:14 PST 2003
.
.
.

The time increments once every second by utilizing the sleep command. Since 6 hasn't yet turned out to be a 9 (to our knowledge), this script most likely will loop forever. If you don't use sleep, you'll waste a lot of CPU power. This can be entered in one line:

until [ 6 -eq 9 ]; do echo $(date); sleep 1; done

Another application of this is to test serial ports. We have a cheap breakout box that has tri-state LEDs, as most breakout boxes do. By running this simple script:

until [ 6 -eq 9 ]; do echo thequickbrownfox > /dev/ttyS0; done

We can tell which line is transmitting data:



The light on pin 2 is orange. If you just hook up the breakout box without the program, the light is red. Pushing a key doesn't help, because the light blinks too fast.

For other stupid BASH tricks, click here.


People:
Places:
Things:
Times:





Please read our Terms of Use and our Privacy Policy
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2010 NetAdminTools.com