[IPython-user] Bash shell scripts to IPython scripts

Phyo Arkar phyo.arkarlwin@gmail....
Mon Oct 27 10:43:47 CDT 2008


Are you new to Python?

Ipython is shell for python . ofcoz you can run the bash script directly
under python.


#!/usr/bin/python

import os
p=os.popen("./report.sh")
print p.strip('/n')


On Sun, Oct 26, 2008 at 7:21 PM, ferrety ferrety <yferrety@gmail.com> wrote:

> 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
> _______________________________________________
> IPython-user mailing list
> IPython-user@scipy.org
> http://lists.ipython.scipy.org/mailman/listinfo/ipython-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ipython.scipy.org/pipermail/ipython-user/attachments/20081027/bacdb681/attachment.html 


More information about the IPython-user mailing list