To add static routes

Yeah, we all go and put a script on /etc/rc2.d or /etc/rc3.d
But to be clean on Solaris 8, 9 and 10 you can add your static routes at /etc/gateways like this:
net 100.100.100.0 gateway 192.1.243.1 metric 1

for Solaris 10 11/06, we can use the “-p” parameter

/usr/sbin/route -p add 175.168.0.0 192.168.2.1

these routes are stored in /etc/inet/static_routes
have fun

check network speed in suse

I wrote a script that shows you in a condensed way if you’re in network card speed trouble:
# ——————— server app213
bond0= eth1 eth2
bond0 : : : : : 10.20.9.38
eth0 : 100Mb/s : Half : on : yes : 192.168.5.119
eth1 : 100Mb/s : Half : on : yes :
eth2 : 100Mb/s : Half : on : yes :
eth3 : Unknown! (65535) : Unknown! (255) : on : no :
Here it goes:
#!/bin/bash
DIR=/tmp/.dir
mkdir $DIR > /dev/null 2>&1
HB=`ifconfig -a | grep -i bond | wc -l | sed ‘s/ //g’`
if [ “$HB” -ne “0” ];then
for i in `ifconfig -a | cut -c0-10 | egrep -i ‘bond’| grep -v ‘:’`;do
echo -n “$i=”
for i in `cat /etc/sysconfig/network/ifcfg-$i | grep “BONDING_SLAVE” | awk -F”=” ‘{ print $2 }’ | awk -F”‘” ‘{
print $2 }’`;do
echo -n ” $i”
done
echo “”
done
fi
for i in `ifconfig -a | cut -c0-10 | egrep -i ‘bond|eth’| grep -v ‘:’`;do
SP=`ethtool $i | grep “Speed:” | awk -F: ‘{ print $2 }’`
DU=`ethtool $i | grep “Duplex:” | awk -F: ‘{ print $2 }’`
AU=`ethtool $i |grep “Auto-negotiation:” | awk -F: ‘{ print $2 }’`
LI=`ethtool $i | grep “Link detected: ” | awk -F: ‘{ print $2 }’`
(for w in `ifconfig $i`;do
echo “$w”
done) | grep “addr:” | awk -F”:” ‘{ print $2 }’ > $DIR/addr
echo “$i : $SP : $DU : $AU : $LI : `cat $DIR/addr` ”
done
set network card speed by default in redhat.
If your interface is eth0, in the etc/sysconfig/network-scripts folder, vi the ifcfg-eth0 script. add the parameters
ETHTOOL_OPTS=”speed 100 duplex full autoneg on”, and you’re set
Next time the server reboots you have the right speed set
215/433
216/433

gawk construct to build a line from each 3 lines

We got the output from “sar -ruq” in a file, we stored in sar2.txt, and it looks like this:

11:44:51 633773 22954346
4 1 3 93
0.0 0 0.0 0
11:44:56 633773 22954288
2 2 1 94
0.0 0 0.0 0
11:45:01 632206 22786120
13 18 13 56
9.0 20 0.0 0
11:45:06 625509 22462685
53 47 0 0
5.0 99 0.0 0

So we want to plot it in excel, we need one line per sample, much like this:

11:45:06 625509 22462685 53 47 0 0 5.0 99 0.0 0
11:45:11 628749 22770298 59 41 0 0 4.8 100 0.0 0
11:45:16 630432 22733837 55 45 0 0 6.8 100 0.0 0

So we wrote a small gawk expression to do it:

gawk 'ORS=NR%3?" ":"n"' sar2.txt

So simple, we’re using the modulus function here to do the job. Coming to a blog near you!

readonly /etc/fstab

If you’re trying to save your /etc/fstab and you get:
“fstab” E212: Can’t open file for writing
And you know you can write any other file in “/”, then it’s not a readonly FS.
You need to check the file’s attributes.
[root@myserver etc]# lsattr /etc/fstab
—-i——– /etc/fstab
if it has a “i” then it’s write protected, so change it
[root@myserver etc]# chattr -i /etc/fstab
[root@myserver etc]# lsattr /etc/fstab
————- /etc/fstab
Then you can edit the file
75/433

NetBackup 101 (for me)

ok, just hang with me while I learn NB.
some jobs were stalled in a machine, so we went to the media server and checked if the jobs were pending
and the tape drives were not in “TSD”:
bash-3.00# /usr/openv/volmgr/bin/vmoprcmd
PENDING REQUESTS
<NONE>
DRIVE STATUS
Drv Type Control User Label RVSN EVSN Ready Wr.Enbl. ReqId
0 dlt TSD – No – –
1 dlt TSD root Yes EBI219 EBI219 Yes Yes 1
ADDITIONAL DRIVE STATUS
Drv DriveName Multihost Assigned Comment
0 QUANTUMDLT70000 No –
1 QUANTUMDLT70001 No ebitdb1
In the “pending” section there were jobs pending on drv 1 and 0, and the tape drives were unavailable, so we
reset them:
# vmoprcmd -deny 0
# vmoprcmd -deny 1
# vmoprcmd -up 0
# vmoprcmd -up 1
We assumed the drives were recently fed with tapes, so after this jobs were running ok.
To see the active jobs…
#bpdbjobs -report |grep -i act
To see the queued jobs…
#bpdbjobs -report | grep -i que
To kill a job
#bpdbjobs -kill <job#>
To see the job summary…
#/usr/openv/netbackup/bin/bpdbjobs -summary
#bpps -a
To run an inventory on a tape library…
#bpinvent 0
259/433
Check last 24 hour’s errors
#bperror -U -backstat -hoursago 24
See available tapes
# available_media
Or go to bpadm – media mgmt – special actions – Inventory a Robot and Compare with Volume Configuration
To see if a tape is in the correct pool
#vmquery -m <mediaid>
To change a tape of pool
# vmchange -h ntxldb2 -p 1 -m NTXD53
(Where 1 is NetBackup and 2 is systems)
To see the pools
#vmpool -listall
A monitoring loop:
# while true;do clear; vmoprcmd; echo “active”; bpdbjobs -report |grep -i act;echo “queued”; bpdbjobs -report
|grep -i que;bpdbjobs -summary; bperror -U -backstat -hoursago 24| tail -15l; sleep 5; clear; done
Run bpadm for interactive actions
# bpadm
document
too
260/433

copy only new files

To make a differential copy, so you copy all files in /a that are not in /b, you can do:
# cd /a
#/usr/local/bin/tar pcf – kraftek.html POSTS rescue rescued.html rescued.txt x y z | ( cd /b; /usr/local/bin/tar kxfp – )
The clue here is the “k” option, to keep existing files
compare directories for missing files
So you made a copy of /a into /b, but you see /b has less files, how to know which files are missing in /b x y z
# find /a | sort > as.txt
# find /b | sort > bs.txt
# comm -23 as.txt bs.txt
the last command will show the files that are in /a that are not in /b
enjoy
192/433

get your top 10 list !!!

To get this week’s top ten from the web, you can first ask billboard using topten.ksh:
#!/bin/ksh
echo “—- getting bilboard’s heatseeker”
curl
158/433
“http://206.130.124.43//htmlsite/html_top.php?id=23&CALL_URL=http%3A//www.billboard.com/bbcom/charts/chart_display.jsp%3Fg%3DSingles%26f%3DHot%2 BDance%2BClub%2BPlay”
> /tmp/bb-hs.txt
cat /tmp/bb-hs.txt | sed -e ‘s/<[^>][^>]*>//g’ -e ‘/^ *$/d;s// /g;s/Featuring//g;s/ the //g’ | tr -s ‘ ‘ | grep “|”|
grep -iv billboard| cut -d ” ” -f4-9 > terms.txt
The top ten list is parsed and ends up as a text only list in “terms.txt”. We now proceed to search and
download the files both from filestube and skreemr, we use a PHP script called mysearch.php to look for files
in filestube(remembver to use your own key for filestube instead of XXXXXXXX):
#!/usr/bin/php
<?php
// Correct English grammar…
$argc > 1 x y z $plural = ‘s’ : $plural = ”;
// Display the number of arguments received
//fwrite(STDOUT, “Got $argc argument$pluraln”);
$args=””;
// Write out the contents of the $argv array
foreach ( $argv as $key => $value ) {
// fwrite(STDOUT,”$key => $valuen”);
if($key!=0){
if($key>1){
$args=”{$args}%20{$value}”;
}else{
$args=”{$value}”;
}
}
}
//print “args are:”;
159/433
//print $args;
$url=”http://api.filestube.com/? key=XXXXXXXXXXXXXXXXXXXXXXX&phrase=$args&extension=mp3&page=1″;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch) ;
print curl_error($ch);
curl_close($ch);
$document = new DOMDocument(‘1.0’, ‘UTF-8’);
$document->loadXML($result);
$answer = $document->getElementsByTagName(‘answer’)->item(0);
if($answer!=null) {
$hasResults = $answer->getElementsByTagName(‘hasResults’)->item(0);
if($hasResults->nodeValue == 1)
{
$hits = $answer->getElementsByTagName(‘hits’);
foreach($hits as $hit)
{
$name = $hit->getElementsByTagName(‘name’)->item(0)->nodeValue;
$extension = $hit->getElementsByTagName(‘extension’)->item(0)->nodeValue;
$desc = $hit->getElementsByTagName(‘description’)->item(0)->nodeValue;
$size = $hit->getElementsByTagName(‘size’)->item(0)->nodeValue;
$address = $hit->getElementsByTagName(‘address’)->item(0) ->nodeValue;
$details = $hit->getElementsByTagName(‘details’)->item(0) ->nodeValue;
$added = $hit->getElementsByTagName(‘added’)->item(0)->nodeValue;
$related = $hit->getElementsByTagName(‘related’)->item(0) ->nodeValue;
$counter=$hit->getAttribute(‘id’);
print “$name | “;
print ” $address nr”;
}
}
else {
print ‘0 resultsnr’;
}
}
else {
$error = $document->get ElementsByTagName(‘error’)->item (0);
if($error!=null){
$message = $error->getElementsByTagName(‘message’)->item(0)->nodeValue;
print ‘Message: ‘.$message.”nr”;
}
}
//——————————-SECOND PAGE!!!
$url=”http://api.filestube.com/? key=XXXXXXXXXXXXXXXXXXXXXXX
&phrase=$args&extension=mp3&page=2″;
$ch = curl_init();
160/433
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch) ;
print curl_error($ch);
curl_close($ch);
$document = new DOMDocument(‘1.0’, ‘UTF-8’);
$document->loadXML($result);
$answer = $document->getElementsByTagName(‘answer’)->item(0);
if($answer!=null) {
$hasResults = $answer->getElementsByTagName(‘hasResults’)->item(0);
if($hasResults->nodeValue == 1)
{
$hits = $answer->getElementsByTagName(‘hits’);
foreach($hits as $hit)
{
$name = $hit->getElementsByTagName(‘name’)->item(0)->nodeValue;
$extension = $hit->getElementsByTagName(‘extension’)->item(0)->nodeValue;
$desc = $hit->getElementsByTagName(‘description’)->item(0)->nodeValue;
$size = $hit->getElementsByTagName(‘size’)->item(0)->nodeValue;
$address = $hit->getElementsByTagName(‘address’)->item(0) ->nodeValue;
$details = $hit->getElementsByTagName(‘details’)->item(0) ->nodeValue;
$added = $hit->getElementsByTagName(‘added’)->item(0)->nodeValue;
$related = $hit->getElementsByTagName(‘related’)->item(0) ->nodeValue;
$counter=$hit->getAttribute(‘id’);
print “$name | “;
print ” $address nr”;
}
}
else {
print ‘0 resultsnr’;
}
}
else {
$error = $document->get ElementsByTagName(‘error’)->item (0);
if($error!=null){
$message = $error->getElementsByTagName(‘message’)->item(0)->nodeValue;
print ‘Message: ‘.$message.”nr”;
}
}
?>
Then we direct all the show with get.ksh:
#!/bin/ksh
#### Get the files from FilesTube
(cat terms.txt| while read line;do
./mysearch.php `echo $line | awk ‘{ print $1 ” ” $2 }’`| grep -i `echo $line | awk ‘{ print $3 }’` | head -1
done) >/tmp/results.txt
(cat /tmp/results.txt | while read result;do
curl “`echo $result | awk -F’|’ ‘{ print $2 }’| sed ‘s/ //g’`” | egrep ‘src.*mp3’ | awk -F”src=”” ‘{ print $2 }’ | awk ‘{
161/433
print $1 }’ | sed ‘s/”//g’
done) | while read url;do
wget -P /200gb/AUTODOWNLOADS “$url”
done
rm /tmp/results. txt
#### Or get them from skreemr
(cat terms.txt| while read line;do
st=`echo $line | awk ‘{ print $1 “+” $2 “+” $3 }’`
wget -P /200gb/AUTODOWNLOADS `curl “http://skreemr. com/results.jsp? q=$st” | egrep ‘href.*mp3’ | awk
-F”href=” ‘{ print $2 }’ | head -1 | sed ‘s/”//g’`
done)
The order of execution is: first “topten.ksh”, to get the list, then “get.ksh” to get the tracks.
Enjoy
162/433