10-24-2006
thanks Nitin & Jean-Pierre!
I'm still trying to get my head aroud the exit code so i understand it fully. Seems like I could have halved the amount of code if i used it. I'll try fiddling with it and get the script to work using exit codes instead of the half ass way I've got it running now.
but,
Here is what i ended up doing. This is my first script that is over about 3 lines long. I know there is a lot of room for improvement and that the writing to a file is a bit of a hack and, I'm sure full of security holes. Suggestions for improvement would be great. ( i did not include the NFS mount command as I have'nt got NFS working on the Apple yet)
HTML Code:
#
# Script that checkins if computer is connected to a specific wireless network (dd-wrt
)
# and then checks to see if a specific ip adress is up(192.168.1.110)
# if the ip adress is down the magic packet is broadcasted in order boot the #approprate machine.
#
NETWORKCOMP="dd-wrt"
/usr/sbin/traceroute umu.se | grep dd-wrt > /tmp/netchk
grep "dd-wrt" /tmp/netchk | awk '{print $2}' > /tmp/netchk2
NETWORK=`cat /tmp/netchk2` # Set the network variable
if [ "$NETWORK" == "$NETWORKCOMP" ]; then
echo "You have access!"
# Remove the temp files
rm /tmp/netchk
rm /tmp/netchk2
GOODPING="icmp_seq=0"
/sbin/ping -c 1 192.168.1.110 | grep icmp > /tmp/pingchk
grep "icmp_seq=0" /tmp/pingchk | awk '{print $5}' > /tmp/pingchk2
REALPING=`cat /tmp/pingchk2`
if [ "$GOODPING" == "$REALPING" ]; then
echo "host is alive, no need to wake up!"
# Remove the temp files
rm /tmp/pingchk
rm /tmp/pingchk2
else
# Remove the temp files
rm /tmp/pingchk
rm /tmp/pingchk2
echo "Host is dead, CLEAR!!"
pythonw /sbin/wol.py
fi
else
echo "Network not found!"
# Remove the temp files
rm /tmp/netchk
rm /tmp/netchk2
fi
Nathan
Last edited by anon0mus; 10-24-2006 at 06:04 PM..
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I need a shell script for OS X, one that can find IP addresses of machines connected to my LAN, get the names of the computer associated with those addresses, then display them like so in a list: "Bob's L33T Boxx: #.#.#.#" Something like the network scanner in Apple Remote Desktop is what I'm... (1 Reply)
Discussion started by: sladuuch
1 Replies
2. UNIX for Advanced & Expert Users
Im old to Unix but new to scripting
I have a MacBook running osx that I want to use as an nfs client. The server will be a linux box with a wake on lan card. Here's the idea. Run a cron command on the mac every minute that checks if I am on my home wireless network (the linux box is wired to... (0 Replies)
Discussion started by: anon0mus
0 Replies
3. Solaris
Hi ,
I am trying to configure a private LAN and corporate LAN on the same machien on Solaris 10.
How can I achieve this?
Thanks (1 Reply)
Discussion started by: deedee
1 Replies
4. Linux
Hi guys,
Two boxes on the same .23 subnet 192.168.1.x
The box I wanted to shutdown and restart remotely
went down, but didn't come back up when I used ether-wake 00:11:22:etc:etc:
The sleeper has two nics, but only one with cable. I configured both nics to wake on lan using the g option.
The... (0 Replies)
Discussion started by: Bloke
0 Replies
5. IP Networking
Hi,
We have a website running on a local centos 5.4 surfer, static IP.
The domain.com uses no-ip.com to take care of the DNS, it forwards all to my server.
My router receives the port 80 call, routes it to my server and the world can see domain.com perfectly fine.
However, we cannot see... (3 Replies)
Discussion started by: lawstudent
3 Replies
6. Red Hat
I am facing strange problem regarding hostname on my Linux(2.6.18-164.el5xen x86_64 GNU/Linux), the hostname changes if reboot with lan cable and with NO lan cable
Reboot with lan cable:
The hostname is ubunut
Unable to connect Oracle database using sqlplus some times database is not... (2 Replies)
Discussion started by: LinuxLearner
2 Replies
7. Shell Programming and Scripting
need perl script to get a comprehend statistic of network activity in a LAN.
The purpose is to get each indivisual data usages statistics so that I can determine who is doing the network congestion in terms of bandwidth usages both in real time and retrospectively..
Thanks in... (4 Replies)
Discussion started by: rrd1986
4 Replies
8. UNIX for Dummies Questions & Answers
As the title implies I'm having trouble setting up Wake-On-LAN with my Debian box. Here is the output from ethtool and my /etc/network/interfaces:
# cat /etc/network/interfaces
# /etc/network/interfaces - configuration file for ifup(8), ifdown(8)
# The loopback interface
auto lo
iface lo... (2 Replies)
Discussion started by: Azrael
2 Replies
9. UNIX for Dummies Questions & Answers
I'm a OS X user (MacBook Pro, OS X Lion) and I need it to wake up on Mondays, Wednesdays, Thursdays and Saturdays at 9:00 AM
on the rest of the days of the week at 7:00
I issue the following commands:
sudo pmset repeat wake MWRS 09:00:00 for the former
sudo pmset repeat wake TFU... (1 Reply)
Discussion started by: scrutinizerix
1 Replies
LEARN ABOUT DEBIAN
script
SCRIPT(1) User Commands SCRIPT(1)
NAME
script -- make typescript of terminal session
SYNOPSIS
script [-a] [-c command] [-e] [-f] [-q] [-t[=file]] [-V] [-h] [file]
DESCRIPTION
script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive
session as proof of an assignment, as the typescript file can be printed out later with lpr(1).
If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript.
Options:
-a, --append
Append the output to file or typescript, retaining the prior contents.
-c, --command command
Run the command rather than an interactive shell. This makes it easy for a script to capture the output of a program that behaves
differently when its stdout is not a tty.
-e, --return
Return the exit code of the child process. Uses the same format as bash termination on signal termination exit code is 128+n.
-f, --flush
Flush output after each write. This is nice for telecooperation: one person does `mkfifo foo; script -f foo', and another can super-
vise real-time what is being done using `cat foo'.
--force
Allow the default output destination, i.e. the typescript file, to be a hard or symbolic link. The command will follow a symbolic
link.
-q, --quiet
Be quiet.
-t, --timing[=file]
Output timing data to standard error, or to file when given. This data contains two fields, separated by a space. The first field
indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time.
This information can be used to replay typescripts with realistic typing and output delays.
-V, --version
Output version information and exit.
-h, --help
Output help and exit.
The script ends when the forked shell exits (a control-D to exit the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not
set) for the C-shell, csh(1)).
Certain interactive commands, such as vi(1), create garbage in the typescript file. Script works best with commands that do not manipulate
the screen, the results are meant to emulate a hardcopy terminal.
ENVIRONMENT
The following environment variable is utilized by script:
SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most
shells set this variable automatically).
SEE ALSO
csh(1) (for the history mechanism), scriptreplay(1).
HISTORY
The script command appeared in 3.0BSD.
BUGS
Script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects.
AVAILABILITY
The script command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
util-linux February 2011 util-linux