strange behaviour sys.argv

schnupfy marcus at schnupfnase.com
Mon Apr 16 21:07:50 EDT 2007


Hi,

I am not used to python and I am wondering about this thing:

If I execute this from the shell:

/root/mk/services.py 192.168.1.101 critical "192.168.1.101
192.168.1.101 SNMPv2-MIB::sysUpTime.0 14:13:02:57.06 SNMPv2-
MIB::snmpTrapOID.0 SNMPv2-SMI::enterprises.789.0.13 SNMPv2-
SMI::enterprises.789.0.2"cfCannotTakeover == 1 priority == critical"
SNMP-COMMUNITY-MIB::snmpTrapAddress.0 192.168.1.101 SNMP-COMMUNITY-
MIB::snmpTrapCommunity.0 "public""

I have the following cmd arguments:

['/root/mk/services.py', '192.168.1.101', 'critical', '192.168.1.101
192.168.1.101 SNMPv2-MIB::sysUpTime.0 14:13:02:57.06 SNMPv2-
MIB::snmpTrapOID.0 SNMPv2-SMI::enterprises.789.0.13 SNMPv2-
SMI::enterprises.789.0.2cfCannotTakeover', '==', '1', 'priority',
'==', 'critical SNMP-COMMUNITY-MIB::snmpTrapAddress.0 192.168.1.101
SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 public']

If I execute the same thing from a bash script:

#!/bin/bash
TRAP='192.168.1.101 192.168.1.101 SNMPv2-MIB::sysUpTime.0
14:13:02:57.06 SNMPv2-MIB::snmpTrapOID.0 SNMPv2-SMI::enterprises.
789.0.13 SNMPv2-SMI::enterprises.789.0.2"cfCannotTakeover == 1
priority == critical" SNMP-COMMUNITY-MIB::snmpTrapAddress.0
192.168.1.101 SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 "public"'
HOST=$(echo "$TRAP" | awk '{print $1}')
SEVERITY='critical'
/root/mk/services.py $HOST $SEVERITY \"$TRAP\"

I get the following result:

['/root/mk/services.py', '192.168.1.101', 'critical',
'"192.168.1.101', '192.168.1.101', 'SNMPv2-MIB::sysUpTime.0',
'14:13:02:57.06', 'SNMPv2-MIB::snmpTrapOID.0', 'SNMPv2-
SMI::enterprises.789.0.13', 'SNMPv2-SMI::enterprises.
789.0.2"cfCannotTakeover', '==', '1', 'priority', '==', 'critical"',
'SNMP-COMMUNITY-MIB::snmpTrapAddress.0', '192.168.1.101', 'SNMP-
COMMUNITY-MIB::snmpTrapCommunity.0', '"public""']

Can someone help me with that?

This is the output of echo /root/mk/services.py $HOST $SEVERITY \"$TRAP
\"

/root/mk/services.py 192.168.1.101 critical "192.168.1.101
192.168.1.101 SNMPv2-MIB::sysUpTime.0 14:13:02:57.06 SNMPv2-
MIB::snmpTrapOID.0 SNMPv2-SMI::enterprises.789.0.13 SNMPv2-
SMI::enterprises.789.0.2"cfCannotTakeover == 1 priority == critical"
SNMP-COMMUNITY-MIB::snmpTrapAddress.0 192.168.1.101 SNMP-COMMUNITY-
MIB::snmpTrapCommunity.0 "public""

Thank you.

Cheers

Marcus




More information about the Python-list mailing list