Category Archives: Linux

Working with files that are named with a timestamp

So I have a script that runs an ls on a given directory and looks for files with a timestamp that has the current hour in it and then does work with the files that it discovers

Code:
DATE=`date +’%y%m%d%H’`
HOSTIS=`hostname`
#EMAIL NOTIFICATION ALS
EMAIL=address@server.com
#

if [ $HOSTIS = ‘serverhostname’ ]; then
TOHOST=’destination_address@destination_server.com’
else
#This is for the test server
TOHOST=’test_address@test_server.com’
fi

for i in `ls /transfer |grep $DATE`
do

sftp -vvv $TOHOST 2>&1 | tee /homedir/user/debug.out
Source: The UNIX and Linux Forums

Extract IP Address from Log File

I have a log file with several IP addresses in it:-

Code:
2012-12-06 16:05:05,885 NOTICE [10674] **SNMP** Alarm was created: (LicenseClientRejected) Client Remote Peer /125.111.64.125:2573 was
Rejected Property=/125.111.64.125:2573, Client Remote Peer /125.111.64.125:2573 was
Rejected **SNMP**. [New I/O server boss #6 ([id: 0x70a81b43, /125.111.64.125:2573])_11]
2012-12-06 16:16:45,739 NOTICE [10674] **SNMP** Alarm was created: (LicenseClientRejected) Client Remote Peer /104.121.98.124:3583 was
Rejected Property=/104.121.98.124:3583, Client Remote Peer /104.121.98.124:3583 was
Rejected **SNMP**. [New I/O server boss #5 ([id: 0x03174ea5, /104.121.98.124:3583])_11]
How can I extract them and list the unique IP addresses using awk or sed ?
Source: The UNIX and Linux Forums

Displaying field of NR, not the line #

Within AWK, how do you display a field of NR? Here’s my code:

Code:
awk ‘(NR>1) && (P1=$1-w)>=100000 {print “increase of” ” ” P1*.0000179,” ” “kW at” ” ” ‘NR*60/431900′ ” ” “minutes” “n” “change from” ” ” ‘NR-10($1)’ ” ” “kW to” ” ” ‘NR+70($1)’ “n”}{w=$1}’ filename
I can change NR and print line #’s, but cannot get a field to print…the error comes at the segment
Code:
NR-10($1)’ ” ” “kW to” ” ” ‘NR+70($1)’

Source: The UNIX and Linux Forums

Giveaways in the next KDE TeaTime (#10)

Almost a month has passed since I wrote on this blog about the show, and so far everything is going great, people seem to be enjoying it and we are having a ton of fun doing it.
Since I talked about it we have done 2 more shows:
KDE TeaTime #8 – If you could change one default setting, what would it be?
http://www.youtube.com/watch?v=wgv0etfJdNE
KDE TeaTime #9 – When to release?
http://www.youtube.com/watch?v=8-pcPeUsznE
And for the next one in order to properly celebrate the #10 show we have prepared some giveaways !

During the show we will explain how to participate in the raffle so make sure to not miss it!

Cheerz!
Source: Planet KDE

sed issue

I’m trying to change a date in a couple of large files using SED. The problem is when I use the -n parameter, it doesn’t actually change the file. When I leave out the -n, it sends the whole file to the screen, but it does appear to change it.

The problem is, these files are very large and it would take forever to change it like that. I’m sure it is just an issue with my syntax, but here is what I was trying:

Code:
sed -n ‘s/20121201/20130101/g’ filename
Should this update the existing file? If not, how can I do that?

Moderator’s Comments:

Code tags please, see PM.

Source: The UNIX and Linux Forums

Manipulating a list into a two-dimensional array

hi,
total newbie to shell scripting and wondering if some of you guru’s can give me a hand on a problem I’m trying to solve.

The tmplsnr.a file contains

Code:
LSNR_51526
db1
db2
LSNR_51527
db3
db4
db5
Summary – depending on which db is set, the script will start the relevant listener (LSNR_). e.g if db5 is set then the script will start the LSNR_51527 listener.

I was thinking the best way maybe to put this information into an array and then search the array.

I want to read the above file into a two dimensional array and the array to looks like this so that I can search the corresponding LSNR for the db.

Code:
LSNR_51526,db1
LSNR_51526,db2
LSNR_51527,db3
LSNR_51527,db4
LSNR_51527,db5
How would I search the array for the listener (LSNR_51527) which relates to db5 ?

Would this method work or have I over complicated things or is there a much simpler method in korn scripting.

I would appreciate any feedback or help

Many Thanks in Advance
Source: The UNIX and Linux Forums

Brackets

Hi all. i need a small help.
i have written an exit code, which will check whether mo.sh is successful or not. if the status is >0 it will exit the shell.
1>Do you guys think it is a correct way to write?
2>what if i change the double bracket to single. how will it change the o/p.

mo.sh
if [[ $? > 0 ]]; then
echo “Patch failed :: $?”
exit 2
fi

thanks in advance
Source: The UNIX and Linux Forums

Running commands on remote machines

so i want to monitor a variety of things on hundreds of servers. the old process was to have an agent running on each one of these servers.

but now i’m looking to see if its possible to have agentless monitoring. the only other straight forward option other than having an agent on the hosts, is to use ssh. but i dont know how to go about this.

I have 2 hosts that will serve as the monitoring servers. One will be Primary, the second will be Backup. the secondary will have the same exact setup as the primary.

what do i need to do on these two hosts to be able to log into all my servers and run the commands i need to run? vmstat, uptime, mpstat etc.

The number of servers i need to monitor is 600.
The OS running on these servers is a mixture of Sun Solaris and Linux Red Hat.
Source: The UNIX and Linux Forums

Solaris on vmware rebooting itself

Hello Admins,
I am facing an issue with Solaris system running/rebooting on vmware. It has VCS installed and configured. It is a 2nd node out of 3-node cluster.
After long time I opened these 3 nodes to run. Rest 2 nodes are running OK. This 1 node is starting and rebooting itself.
Attached is the screen shot I took. I also disabled VCS to start across reboot. But it didnt work.

Let me know how to get it into work.

Thanks.

Attached Images

File Type: jpg
VCS-node2.jpg (233.7 KB)

Source: The UNIX and Linux Forums