[IPython-user] Bash shell scripts to IPython scripts

ferrety ferrety yferrety@gmail....
Tue Oct 28 07:49:21 CDT 2008


Hi Phyo,

Thanks for this solution but it's not excatly what I want !!!

What l'm looking after is a mix between the Python power and shell.
So, IPython. Now, could I save IPython command on a file, but not with
the logging facilities.

It could be very helpfull for me if that was possible.

Anyway, thanks

Regards
Ferret


On Mon, Oct 27, 2008 at 4:43 PM, Phyo Arkar <phyo.arkarlwin@gmail.com> wrote:
>
> 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
>
>


More information about the IPython-user mailing list