[IPython-user] Bash shell scripts to IPython scripts

ferrety ferrety yferrety@gmail....
Sun Oct 26 14:21:47 CDT 2008


Hi List,

I'm new to IPython, I just discovred it ysterday and I was surprised
bu its powerfullness.
So, let's suppose the following shell script (report.sh). It's simply
output the IP adresses of my box
and some other stuffs and it's called as a "cron" job each 5 minutes.

-8-8-8-8 snip -8-8-8-8 snip -8-8-8-8
#!/usr/bin/env bash
OS=`uname`
IO="" # store IP

case $OS in
    Linux) IP=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' |
cut -d: -f2 | awk '{ print $1}'`;;

    FreeBSD|OpenBSD|Darwin) IP=`ifconfig  | grep -E 'inet.[0-9]' |
grep -v '127.0.0.1' | awk '{ print $2}'` ;;

    SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{
print $2} '` ;;
    *) IP="Unknown";;
esac
# other stuffs here ...
echo "$IP"

-8-8-8-8 snip -8-8-8-8 snip -8-8-8-8

Now, I'd like to change this bash script and move to an IPython version of it.
I can easily start with:

-8-8-8-8 snip -8-8-8-8 snip -8-8-8-8

$ ipython -p sh
Leopard libedit detected.
IPython 0.9.1   [on Py 2.5.1]

[/tmp]|1> !./report.sh
192.168.1.3
10.37.129.2
10.211.55.2
[/tmp]|2>

-8-8-8-8 snip -8-8-8-8 snip -8-8-8-8

But how can I save this in a session (i.e file on disk) to be able to
reply that session as a "cron" job (not manually)?

Advices will be very welcome.

Regards
Ferret


More information about the IPython-user mailing list