Example:
string1 = 'It is so cold outside'
array = string1.split(' ')
Check array:
print array
['It', 'is', 'so', 'cold', 'outside']
Convert array to string:
string2 = ' '.join(array)
Check string2:
print string2
'It is so cold outside'
Just for fun:
string2 = '-'.join(array)
Check string2:
print string2
'It-is-so-cold-outside'
Thursday, October 9, 2014
Wednesday, October 8, 2014
Covert string variable to array in bash script
The syntax is:
array=($string)
Following is an example:
string="where am I?"
array=($string)
Check:
for i in ${array[@]}; do echo $i; done
where
am
I?
Convert array to string variable:
for i in ${array[@]}; do abc="$abc `echo $i`"; done
Check:
echo $abc
where am I?
Additional array info:
${arr[*]} # All of the items in the array
${!arr[*]} # All of the indexes in the array
${#arr[*]} # Number of items in the array
${#arr[0]} # Length of item zero
Append new element to array:
arr=(${arr[@]} element)
arr+=(element)
array=($string)
Following is an example:
string="where am I?"
array=($string)
Check:
for i in ${array[@]}; do echo $i; done
where
am
I?
Convert array to string variable:
for i in ${array[@]}; do abc="$abc `echo $i`"; done
Check:
echo $abc
where am I?
Additional array info:
${arr[*]} # All of the items in the array
${!arr[*]} # All of the indexes in the array
${#arr[*]} # Number of items in the array
${#arr[0]} # Length of item zero
Append new element to array:
arr=(${arr[@]} element)
arr+=(element)
Wednesday, April 17, 2013
Load Average is Difference Between Uptime and Snmpwalk
Following example shows the difference between uptime and snmpwalk commands.
# uptime
12:13:48 up 580 days, 51 min, 8 users, load average: 2.38, 1.70, 2.70
# snmpwalk -v2c -c public localhost .1.3.6.1.4.1.2021.10.1.5
UCD-SNMP-MIB::laLoadInt.1 = INTEGER: 243
UCD-SNMP-MIB::laLoadInt.2 = INTEGER: 172
UCD-SNMP-MIB::laLoadInt.3 = INTEGER: 270
# snmpwalk -v2c -c public localhost .1.3.6.1.4.1.2021.10.1.6
UCD-SNMP-MIB::laLoadFloat.1 = Opaque: Float: 2.240000
UCD-SNMP-MIB::laLoadFloat.2 = Opaque: Float: 1.690000
UCD-SNMP-MIB::laLoadFloat.3 = Opaque: Float: 2.680000
Snmp has 2 oids for load average, integer and floating point. The value of floating point is the same as uptime, To convert integer load average value from snmpwalk, simplely devide it by 100.
# uptime
12:13:48 up 580 days, 51 min, 8 users, load average: 2.38, 1.70, 2.70
# snmpwalk -v2c -c public localhost .1.3.6.1.4.1.2021.10.1.5
UCD-SNMP-MIB::laLoadInt.1 = INTEGER: 243
UCD-SNMP-MIB::laLoadInt.2 = INTEGER: 172
UCD-SNMP-MIB::laLoadInt.3 = INTEGER: 270
# snmpwalk -v2c -c public localhost .1.3.6.1.4.1.2021.10.1.6
UCD-SNMP-MIB::laLoadFloat.1 = Opaque: Float: 2.240000
UCD-SNMP-MIB::laLoadFloat.2 = Opaque: Float: 1.690000
UCD-SNMP-MIB::laLoadFloat.3 = Opaque: Float: 2.680000
Snmp has 2 oids for load average, integer and floating point. The value of floating point is the same as uptime, To convert integer load average value from snmpwalk, simplely devide it by 100.
Retrieve system information with facter
The facter is a Ruby tool that provides system information in "key=>value" pairs. Following are some examples:
# facter
architecture => x86_64
...
is_virtual => false
...
memoryfree => 20.15 GB
...
netmask => 255.255.255.0
...
# facter timezone
EDT
# facter
architecture => x86_64
...
is_virtual => false
...
memoryfree => 20.15 GB
...
netmask => 255.255.255.0
...
# facter timezone
EDT
Thursday, April 11, 2013
Use Jenkiz to monitor Cron Job with hudson_wrapper
The easest way to use Jenkinz to monitor cron job is use hudson_wrapper as show below:
1. Put hudson_wrapper.sh, from https://github.com/joemiller/hudson_wrapper, on each server, and update the /etc/crontab as below:
0 * * * * root /path/hudson_wrapper.sh Jenkinz_URL name command
2. The wrapper will create the job on the Jekniz server if it is not exist. So no Jenkiz configuration needed.
1. Put hudson_wrapper.sh, from https://github.com/joemiller/hudson_wrapper, on each server, and update the /etc/crontab as below:
0 * * * * root /path/hudson_wrapper.sh Jenkinz_URL name command
2. The wrapper will create the job on the Jekniz server if it is not exist. So no Jenkiz configuration needed.
Top command issue on cron job
Use -b option to run top command through cron and extend script for snmp configuration, etc. Otherwise top will failed with "top: failed tty get" message.
top -b -n 1
top -b -n 1
Trick for SVN Folder defination in authz file
Don't put a slash at the end of a folder defination such as [/SYSTEMS/] instead of [/SYSTEMS]. The ending slash may cause access denied problem.
Subscribe to:
Posts (Atom)