Sometimes it is necessary to check whether server you want to run some big bash script is connected to Internet. Usually it makes sense while running scripts periodically using cron. Below is the tiny bash script for this purpose:
#!/bin/bash
WGET="/usr/bin/wget"
$WGET -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
if [ ! -s /tmp/index.google ];then
echo "no"
else
echo "yes"
fi
As you see it tries to download google’s index page, if it’s not empty script returns “yes”, if there is not Internet connection available script will return “no”. If it is impossible to fetch the page in more than 5 seconds script will return “no” as well.
Anything to add? You are welcome!
Well, IBM publishes a new article about useful Unix command line habits as a follow-up to Michael Stutz’s article. I promise that after reading this article you will say something like “A-ha, I didn’t know you could do that!”
Here is the part of that staff:
The !$ command returns the last argument used with a command. But what happens if you have a command that used arguments and you want to reuse just one of them? The !:1 operator returns the argument used in a command. The example in Listing 3 shows how you can use this operator in combination with the !$ operator. In the first command, a file is renamed to a more meaningful name, but to preserve use of the original file name, a symbolic link is created. The file kxp12.c is renamed in a more readable manner, then the link command is used to create a symbolic link back to the original file name, in case it’s still used elsewhere. The !$ operator returns the file_system_access.c argument, and the !:1 operator returns the kxp12.c argument, which is the first argument of the previous command.
Listing 3
$ mv kxp12.c file_system_access.c
$ ln –s !$ !:1
Read more here…

You may already be known that Microsoft claims that Windows PowerShell (comes with its Vista by default) script language helps IT professionals achieve greater control and productivity and to accelerate the automation during system administration process. As a non-Windows but *nix systems administrator/engineer I was always interested if it is possible to access those functions and objects we can easily get in Bash (of course we are talking about each operation system’s specific procedures and objects).
And these days I came across a good article “Shell Games” (by Marcus Nasarek) telling about above mentioned matters…
Both Bash and the Windows Vista PowerShell include commands for navigating directories, managing files, and launching other programs. System administration is an important duty for the shell, and Bash and PowerShell are equipped to help manage systems from the command prompt. Whereas Bash typically relies on a combination of newer tools and classic Unix utilities, the PowerShell has its own set of command-line programs. Windows refers to PowerShell commands as cmdlets. The PowerShell cmdlet called Get-Process is a counterpart to ps, and the cmdlet Get-Content corresponds to less. PowerShell differs significantly from previous Windows command shells. In this article, I look at how Windows Vista PowerShell compares with Bash. Read more >>
More useful links:
1. Microsoft PowerShell official page
2. Bash Reference Manual
3. GNU Bash for Windows
Date: October 5, 2007. Categories:
shell.
Well known security expert H.D. Moore published entertaining article on how to make your Apple iPhone to be a hacking platform…
Having a network-enabled root shell in my pocket is great, but being able to pop a root shell on someone else’s iPhone is even better. A few things to keep in mind:
Every process runs as root. MobileSafari, MobileMail, even the Calculator, all run with full root privileges. Any security flaw in any iPhone application can lead to a complete system compromise. A rootkit takes on a whole new meaning when the attacker has access to the camera, microphone, contact list, and phone hardware. Couple this with “always-on” internet access over EDGE and you have a perfect spying device.
Read more…
ipcad is IP accounting daemon with Cisco-like ip accounting export. It runs in background, listens traffic on the specified interfaces, and records the traffic for later retrieval and analysis.
Here is a piece of shell code that allows to export ipcad output into sqlite3 database format:
echo "create table traffic (src, dst, pkt, bt);" | sqlite3 /tmp/throttle.db
rsh 127.0.0.1 show ip accounting | grep "^ " | grep -vi source | awk \
'{print"insert into traffic values (\""$1"\",\""$2"\",\""$3"\",\""$4"\");"}' \
| sqlite3 /tmp/throttle.db
To make this working ipcad should be configured not to capture ports and to enable rsh service. In my case ipcad has the following settings set in ipcad.conf:
capture-ports disable;
interface eth0;
rsh enable at 127.0.0.1;
rsh 127.0.0.1 admin;
rsh ttl = 3;
rsh timeout = 30;
pidfile = /var/run/ipcad.pid;
memory_limit = 100m;
and output (rsh 127.0.0.1 show ip accouting) is like:
192.168.0.7 192.168.0.1 113241 166387462
192.168.0.1 192.168.0.7 72117 4282846
192.168.0.77 66.235.184.245 2448 821095
66.235.184.245 192.168.0.77 3995 697371
The main problem is that it sqlite3 is rather slow and it takes eleven (11!!!) seconds to export 1000 entries of ipcad’s output into database. This was got at PC with 1.4Ghz CPU and 512Mb RAM.
If anybody knows how to get it faster, PLEASE LET ME KNOW! Thanks.
Information Improvisation: Traffic Engineering Server is new Solution for Bandwidth Management and QoS. It’s especially suitable for Broadband ISPs and SMEs.
Recent Ideas