Posts filed under 'Unix / Linux'
This is a simple shell script that i used often to search and replace a string when I have multiple files within multiple folders. It is very useful when you need to search and replace a text in a folder with multiple files. Feel free to use and modify it to suit your need.
cd $1
for folder in *
do
echo “$folder”
cd “$folder”
echo -n “Your current dir is ”
pwd
for fl in *.htm;
do
mv $fl $fl.old;
sed ’s/string-to-search/replace-with-this-string/g’ $fl.old > $fl;
done
rm -rf *.old
chown owner.owner *.htm
cd ..
echo “Done … getting next folder”
sleep 5s
done
To use the code, create a file named changer, insert the above code. Then, chmod 755 the created file. Place the file outside the folder that you are trying to work on. Then execute, ./changer foldername, where foldername is the folder you are working on.
July 11th, 2006
I ran into this alert or error message almost all the time after installing a new Apache server. Everytime I do a restart on the apache server, it will say:
[alert] httpd: Could not determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName
Since this is just an alert and Apache try to fix this issue automatically by assigning the server’s fully qualified domain name to 127.0.01 for servername. But you can always fix this by defining the ServerName within the http.conf file. So for example you have a hostname named stereo, then you will add the following to your httpd.conf:
ServerName stereo
You can always find out your server’s hostname by typing hostname. Then you might also want to speficy the following in your /etc/hosts file:
127.0.0.1 stereo localhost localhost.localdomain
April 15th, 2006
Time for a new project. A new 50 Mbits server that I ordered last monday is up and running. It took about 5 days for the server setup. Tried to login as root and got this message.. “Password auth with the SSH2 server failed”…
So what is wrong.. I did double check the username and password and still can’t log in. Next, time to contact the network administrator. They responded to me saying they did make a boo-boo. They gave me the wrong IP address the first time and appologized to me. Thats ok.. people do make a mistake once in a while hehe
Now, that I have the correct IP address… time to mess with the server… first move is to check on system information..
Those commands executed as shown in the picture confirm that the server is an Intel P4 2.8 Ghz CPU with 1MB L2 Cache, 1024 MB of DDR RAM, and 80 GB of disk space. That is about all the information I need to know for now. Maybe execute the command to confirm the Linux distribution as well using cat /etc/issue and it says CentOS release 4.2 (Final). That is what I expected.
A speed test done using wget to kernel.org shows us that the download speed is about 1.86 Mbps, which is a significantly good download speed within the continental U.S. The rest would be to fix the machine time, hostname, services, speed and other things to suit the usage. Time to mess with it again..
April 15th, 2006
I have not been using shoutcast for long. But here is the unix shell script to autostart your shoutcast server or any other services once it is down. First create a blank file on your shell command like this
touch autostart-shoutcast
Then use your favorite text editor program such as nano, pico or vi and insert the following unix shell script:
#!/usr/bin/perl
@a=qx{ps x | grep -i shoutcast-radio};
$b=1;
foreach (@a) {
if ($_ =~ /grep/) {
$_ =~ s/.*/blah/g;
}
if ($_ =~ /shoutcast-radio/) {$b=0;}
}
if ($b == 1) {
print “Starting up\n”;
qx{cd ~/shoutcast/ ; ./shoutcast-radio &> /dev/null &};
}
Make sure it is executable, using the chmod command like below:
chmod 755 autostart-shoutcast
Finally setup your crontab like below:
0,10,20,30,40,50 * * * * /home/shoutcast/autostart-shoutcast &> /dev/null
April 6th, 2006
It has been quite a while since my new post. I have been enjoying my summer so far and I am taking less classes so that I could enjoy the holiday at the same time complete a couple of units. Here is an update on the server uptime from my last few postings. The mentioned server has now reached an incredible 259 days… I think it could surpass that 1 year boundary. I know people are saying out there that a system with no latest kernel update could lead to an insecure system. I am well aware of that. It is again depends on your system application and for this case it does not need that latest kernel update.
[root@liberty root]# uptime
3:45am up 259 days, 18:24, 2 users, load average: 0.00, 0.00, 0.00
[root@liberty root]# date
Fri Jul 29 03:45:35 PDT 2005
[root@liberty root]#
The machine has a dual Pentium Xeon 2.4 Processors and 2GB of RAM
[root@liberty root]# cat cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.40GHz
stepping : 7
cpu MHz : 2400.182
cache size : 512 KB
physical id : 0
siblings : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
[root@liberty root]# cat meminfo
MemTotal: 2076268 kB
MemFree: 50768 kB
Buffers: 19468 kB
Cached: 1802320 kB
SwapCached: 0 kB
Active: 912604 kB
Inactive: 1014732 kB
HighTotal: 1179584 kB
HighFree: 768 kB
LowTotal: 896684 kB
LowFree: 50000 kB
SwapTotal: 3035628 kB
SwapFree: 3035052 kB
Dirty: 1936 kB
Writeback: 0 kB
Mapped: 119952 kB
Slab: 83228 kB
CommitLimit: 4073760 kB
Committed_AS: 753832 kB
PageTables: 4788 kB
VmallocTotal: 114680 kB
VmallocUsed: 1848 kB
VmallocChunk: 112788 kB
A nice stable machine indeed..!
July 29th, 2005
One of my server running an old Red Hat Linux OS has reached 209 days of uptime. As you can see, the load on this particular machine is not stressed that much. A great stable system and I am happy to see such an uptime…
[root@liberty root]# uptime
8:09pm up 209 days, 10:48, 1 user, load average: 0.00, 0.00, 0.00
[root@liberty proc]# date
Wed Jun 8 20:11:38 PDT 2005
June 8th, 2005