Tag Archives: FILE

How to search a filename stored in a variable using a pattern?

By Little

hi,

i have a variable which contains some file names delimited by a single space.

Code:

FNAME="s1.txt s2.lst s3.cvs s4.lst"


i have another variable that contains a pattern

Code:

FILE_PATTERN="*.lst"


i want to take the filenames from FNAME variable and assign each file name in to an array say
for example:- *.lst will match two files that are s2.lst and s4.lst, so i want to assign s2.lst and s4.lst to a array

Code:

FILE[0]="s2.lst"
FILE[1]="s4.lst"


can anyone say how can i do the above.?

Thanks

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Read sequence file into linked list in C.

By yifangt

Sounds like a homework, but not! This is only for self study. I know the better way would be in perl which is too slow if the file is too big (normally ~15GB), but I am trying to pick up C said to be more faster and use less memory. Can someone help me with my code? Here’s the file (which is a typical fastq format—mean every four lines as a unit): infile.txt

Code:

@Mseq1
AGCTG
+
XX%%A
@Mseq2
AGCGG
-
&X#%A
@Mseq3
AGCCG
+
#X%#A


Desired Output: outfile.txt

Code:

@Mseq1 AGCTG + XX%%A
@Mseq2 AGCGG - &X#%A
@Mseq3 AGCCG + #X%#A


Code:

#include
#include
#include

struct node
{
char readName[251];
char readSeq[251];
char strand;
char readQual[251];
struct node *next;
};

int main ()
{
FILE *fp;
int count;
char *line;
count = 1;
char filename[30] = "infile.txt";
struct node *read, *pre, *p;
struct node *first = NULL;

fp = fopen (filename, "r");

while (fgets (line, sizeof (line), fp) != NULL) /* read a line */
{
read = (struct node *) malloc (sizeof (struct node));
while (count % 4 == 1)
{
strcpy (read->readName, line);
}
count++;
while (count % 4 == 2)
{
strcpy (read->readSeq, line);
}
count++;
while (count % 4 == 3)
{
strcpy (read->strand, line);
}
count++;
while (count % 4 == 0)
{
strcpy (read->readQual, line);
}
count++;
read->next = NULL;
pre = p = first;

while (p != NULL)
{
pre = p;
p = p->next;
}
if (pre != NULL)
pre->next = read;
else
first = read;

fclose (fp);

...read more

Source: FULL ARTICLE at The UNIX and Linux Forums

FTP connection refused issue

By sharsour

Hi All,

I am using the below script to get some files from the remote location

Code:


HOST='Test03'
USER='root'
PASSWD='*****'
FILE='/home/user/d.txt'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
get $FILE
quit
END_SCRIPT
exit 0



But ist is giving me the error “Connection refused”

I am giving the right username , password and hostname. I dont have to apply the ssh-keys as i want to do it by giving password.

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Unpredictable result with echo command when used in a for loop

By Pabi

I am trying to write a small shell script to find out the signed and unsigned jars in particular directory. While the script works fine until 4-5 jars, it starts showing unpredictable results if my directory has more jars ( currntly about 25 jars). I am not sure but a possible reason for this might be related to buffering of STDIN/STDOUT. I tried to find a resolution for this in related posts but could not get a clear answer.

Here goes my script: ( it takes JAVA_HOME as an argument ):

Code:

#! /bin/bash
JV_HOME=$1

for i in `ls *.jar`
do
echo "scanning $i ..."
FILE=$i
$JV_HOME/bin/jarsigner -verify -verbose -certs $FILE | grep "jar verified" ;
if [ $? -eq 0 ]; then
echo "n$FILE is code-signedn"
else
echo "n$FILE is unsigned/unverified..n"
fi
done


——————————————–

For some of the jars, it says the jar to be unsigned, when they are actually signed when checked individually with the following command:

$JAVA_HOME/bin/jarsigner -verify -verbose -certs

What could possibly be wrong with the above script?

Thanks in advance,
Pabi

From: http://www.unix.com/shell-programming-scripting/221241-unpredictable-result-echo-command-when-used-loop.html

Reading XML in bash and importing in Mysql

By garf0r

Hi,
I’m not a pro bashscript writer but I’m learning and want to learn about my mistakes.
In the next script I have an error on rule 6 but I can’t find what I’m doing wrong …
I daily receive a file xml.xml and have to import it in an mysql database in a few existing tables.

Code:

#!/bin/bash
FILE="/transfer/store/xml.xml"
RESULT=$(xmlstarlet sel -t -v "count(//Appointment)" $FILE)
_DB_TABLE_PERSONS="persons"
_DB_TABLE_INVITATIONS="invitiations"
FOR (( i=0; i<$RESULT; i++ )) ; DO
PFIRST_NAME="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/data1 $FILE)"
PLAST_NAME="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/data2 $FILE)"
PADDRESS="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/data3 $FILE)"
PTELEPHONE="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/data4 $FILE)"
PEMAIL="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/email $FILE)"
VALUES(NULL,'${FIRST_NAME}','${LAST_NAME}','${ADDRESS}','${TELEPHONE}','${EMAIL}');"
QUERY="INSERT INTO ${_DB_TABLE_PERSONS} ('id','first_name','last_name','address','telephone','email') VALUES(NULL,'${PFIRST_NAME}','${PLAST_NAME}','${PADDRESS}','${PTELEPHONE}','${PEMAIL}');"
mysql --host=10.1.12.69 --user=test --password=test --database=test < $QUERY
ID_PERSONS=$(mysql --host=10.1.12.69 --user=test --password=test --database=test -se "SELECT LAST_INSERT_ID()")
IREMARK="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/data5 $FILE)"
ELAST_NAME="$(xmlstarlet sel -t -v //Appointment[${i}+1]/transfer-info/name $FILE)"
ID_EMPLOYEES=$(mysql --host=10.1.12.69 --user=test --password=test --database=test -se "SELECT id FROM employees WHERE last_name=${ELAST_NAME}")
LNAME="$(xmlstarlet sel -t -v //Appointment[${i}+1]/transfer-info/locatiebenaming $FILE)"
ID_LOCATIONS=$(mysql --host=10.1.12.69 --user=test --password=test --database=test -se "SELECT id FROM locations WHERE UCASE(name) like '%${ELAST_NAME}%'")
ID_I_TEMP="$(xmlstarlet sel -t -v //Appointment[${i}+1]/Date $FILE)"
IT_I_TEMP="$(xmlstarlet sel -t -v //Appointment[${i}+1]/Time/Begin $FILE)"
IDATE_INVITATION=${ID_I_TEMP:0:4}-${ID_I_TEMP:4:2}-${ID_I_TEMP:6:2}
IEXPIRATION_DATE=${IT_I_TEMP:0:2}-${IT_I_TEMP:2:2}
QUERY="INSERT INTO ${_DB_TABLE_INVITATIONS} ('id','person','employee','location','date_invitation','time_invitation','notification','remark') VALUES(NULL,'${PFIRST_NAME}','${PLAST_NAME}','${PADDRESS}','${PTELEPHONE}','${PEMAIL}');"
mysql --host=10.1.12.69 --user=test --password=test --database=test < $QUERY
DONE


XML:

Code:

20130409

1830
1900

bla
m00
street 10
0000/000000
subject
remarks

BARBRE5
TESTPERSON
TESTLOCATION
3702
45784139

20130412

1600
1730

bla2
m002
street 666
0000000000
andere

mailaddress2

BIRBRE5
TESTPERSON2
TESTLOCATION2
5802
4578487


From: http://www.unix.com/shell-programming-scripting/220839-reading-xml-bash-importing-mysql.html

Help on lookup script

By prashantv

Hi All,

I’ve had a look around the forum but cannot find any answers for what I want to do.

I have 2 files :

FILE 1
===============

ter049107
ter049048
2013-04-09 08:15:16
ter049056
ter049083
ter049112
2013-04-09 10:35:10
2013-04-09 10:29:47
2013-04-09 07:44:05

FILE 2 – note the space is tab seperated
==================

ter049048 Dave
ter049056 Robert
ter049083 John
ter049112 Tom
ter049107 Bob

Output Required
==================

ter049107 – Bob
ter049048 – Dave
2013-04-09 08:15:16
ter049056 – Robert
ter049083 – John
ter049112 – Tom
2013-04-09 10:35:10
2013-04-09 10:29:47
2013-04-09 07:44:05

I’ve been trying it with Awk but can’t get it to work correctly.
Any help would be very appreciated.

Thanks
P

Source: FULL ARTICLE at The UNIX and Linux Forums

Adding a specified value to a specified column – awk?

By radudownload

Hi everyone!

I sometimes need to do some simple arithmetics, like adding a number to a certain column of a file. So I wrote a small function in the .bashrc file, which looks like this

Code:

shifter()
{
COL=$1
VAL=$2
FILE=$3

cp $FILE $FILE.shifted
awk 'NF==4 {$(( $COL )) = $(( $COL )) + $VAL}' $FILE.shifted
}


which should add the number stored in VAL, to the column COL from the FILE file.

Please give me a hint how should I make this work. Thank you! (I’m just a newbie in shell programing)

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Cannot correctly connect multi-stage C command pipe (among others) (FYI: a lot of code)

By kowit010

Use and complete the template provided. The entire template must be completed. If you don’t, your post may be deleted!

1. The problem statement, all variables and given/known data:

We are supposed to write a C program that parses a command line, separates it into each command (further separates each command into its argument vectors), and then creates a multi-stage execution pipeline.

Example: “ls -l | grep ^d | wc -l”

The program must also print the results to a LOGFILE of each command created, the PIDs of each command, and the exit status of all commands. Finally, the program needs to wait for each program to execute, kill each command if Cntl-C is hit while the pipeline is executing and start over, or simply end the program if Cntl-C is hit beforehand.

2. Relevant commands, code, scripts, algorithms:

This is the code we have to work with. I apologize for the super-long massive block of code, and any problems with formatting or displaying this properly here, but this is what we must work with, and believe me, no one is more frustrated trying to comprehend this than me, since I am not very good at C programming:

file: piper.c

Code:

/***********************************************************************************************

CSci 4061 Spring 2013
Assignment# 3: Piper program for executing pipe commands

Student name: [hidden for confidentiality], [hidden for confidentiality]
Student ID: [hidden for confidentiality], [hidden for confidentiality]
X500 id: [hidden for confidentiality], [hidden for confidentiality]

Operating system on which you tested your code: Linux
CSELABS machine: [hidden for confidentiality]

GROUP INSTRUCTION: Please make only ONLY one submission when working in a group.

***********************************************************************************************/

#include
#include
#include
#include
#include
#include
#include
#include <errno.h>
#include

#define DEBUG

#define MAX_INPUT_LINE_LENGTH 2048 // Maximum length of the input pipeline command
// such as "ls -l | sort -d +4 | cat "
#define MAX_CMDS_NUM 8 // maximum number of commands in a pipe list
// In the above pipeline we have 3 commands
#define MAX_CMD_LENGTH 256 // A command has no more than 255 characters

volatile int interrupt = 0;//used for handling Cntl-C
FILE *logfp;

int run=1,run2=1;
int prev[2],curr[2];
int num_cmds = 0;
char *cmds[MAX_CMDS_NUM+1];
char *cmds2[MAX_CMDS_NUM+1][256];
int cmd_pids[MAX_CMDS_NUM];
int cmd_status[MAX_CMDS_NUM];
int stat;
int printCount=1,success=0;

/*******************************************************************************/
/* ...read more
Source: FULL ARTICLE at The UNIX and Linux Forums

URGENT:Cannot correctly connect multi-stage C command pipe (among others) (FYI: a lot of code)

By kowit010

Use and complete the template provided. The entire template must be completed. If you don’t, your post may be deleted!

1. The problem statement, all variables and given/known data:

We are supposed to write a C program that parses a command line, separates it into each command (further separates each command into its argument vectors), and then creates a multi-stage execution pipeline.

Example: “ls -l | grep ^d | wc -l”

The program must also print the results to a LOGFILE of each command created, the PIDs of each command, and the exit status of all commands. Finally, the program needs to wait for each program to execute, kill each command if Cntl-C is hit while the pipeline is executing and start over, or simply end the program if Cntl-C is hit beforehand.

2. Relevant commands, code, scripts, algorithms:

This is the code we have to work with. I apologize for the super-long massive block of code, and any problems with formatting or displaying this properly here, but this is what we must work with, and believe me, no one is more frustrated trying to comprehend this than me, since I am not very good at C programming:

file: piper.c

Code:

/***********************************************************************************************

CSci 4061 Spring 2013
Assignment# 3: Piper program for executing pipe commands

Student name: [hidden for confidentiality], [hidden for confidentiality]
Student ID: [hidden for confidentiality], [hidden for confidentiality]
X500 id: [hidden for confidentiality], [hidden for confidentiality]

Operating system on which you tested your code: Linux
CSELABS machine: [hidden for confidentiality]

GROUP INSTRUCTION: Please make only ONLY one submission when working in a group.

***********************************************************************************************/

#include
#include
#include
#include
#include
#include
#include
#include <errno.h>
#include

#define DEBUG

#define MAX_INPUT_LINE_LENGTH 2048 // Maximum length of the input pipeline command
// such as "ls -l | sort -d +4 | cat "
#define MAX_CMDS_NUM 8 // maximum number of commands in a pipe list
// In the above pipeline we have 3 commands
#define MAX_CMD_LENGTH 256 // A command has no more than 255 characters

volatile int interrupt = 0;//used for handling Cntl-C
FILE *logfp;

int run=1,run2=1;
int prev[2],curr[2];
int num_cmds = 0;
char *cmds[MAX_CMDS_NUM+1];
char *cmds2[MAX_CMDS_NUM+1][256];
int cmd_pids[MAX_CMDS_NUM];
int cmd_status[MAX_CMDS_NUM];
int stat;
int printCount=1,success=0;

/*******************************************************************************/
/* ...read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Loop and array problem

By hubleo

Hi, I have the following problem that is beyond what I can currently do with bash scripting.

In file 1, I have ~ 2500000 values. Note this file is not sorted.

Code:

3 19 LABEL_A
3 37 LABEL_B
2 12 LABEL_C
1 15 LABEL_D


I have a list of values in “file 2” ~ 25000 unique lines:
Note – LABEL_7 AND LABEL_8 overlap slightly in their column 2 and 3 values

Code:

1 11 20 LABEL_1
1 18 30 LABEL_2
1 31 40 LABEL_3
2 11 20 LABEL_4
2 21 30 LABEL_5
2 31 40 LABEL_6
3 11 20 LABEL_7
3 15 30 LABEL_8
3 31 40 LABEL_9
4 11 20 LABEL_10


ETC

To run through what I would like to do, as an example:

LABEL_A (FILE 1) has a 3 in column 1, and a value of 19 in column 2.
I want to compare this to every line in FILE 2.

So, if there is a 3 in column 1 of FILE2, and 19 is between the values of columns 2 and 3 of FILE2, see what label this corresponds to in FILE2.

In this example, 19 is between the values in column 2 and 3 (FILE2) for LABEL_7 and LABEL_8.

Desired output: (Note the value of 2 in column 4 below means there are 2 labels that contain the value 19).

Code:

LABEL_A LABEL_7 LABEL_8 2


Full output:

Code:

LABEL_A LABEL_7 LABEL_8 2
LABEL_B LABEL_9 1
LABEL_C LABEL_4 1
LABEL_D LABEL 1 1


I think the code for this will involve while loops and arrays, but I have no idea where to start. Any bash solutions would be great (as this is what I am currently learning), but any assistance at all would be very much appreciated.

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

James Hunt: Upstart 1.8 released

Hot on the heels of Upstart 1.7 comes Upstart 1.8 which includes two interesting new features:

The File Bridge

Upstart now provides the upstart-file-bridge, a bridge that allows jobs to react to file events.

Here are a few examples:

Start a job when file is created, modified or deleted:

start on file FILE=/run/app.pid

Start job when file is created (only):

start on file FILE=/run/app.pid EVENT=created

Start job when any files within a directory are created, modified or deleted:

start on file FILE=/var/log/

Start job when files that match a glob pattern are created in the indicated directory:

start on file FILE=/var/crash/*.crash EVENT=created

Even better, this bridge is available to both system jobs and users session jobs.

See upstart-file-bridge(8) and file-event(7) for further details.

The GUI

The upstart-monitor tool covered in a previous post has also been added to the release. This allows you to see what events Upstart is emitting and how jobs are changing state both at the system and user session levels.

You can download Upstart 1.8 from:

Upstart 1.8 should be landing in Ubuntu Raring in the next few days. Thanks to all involved!

Contributions

If you are interested in contributing to Upstart, we’d love to hear from you. Now is a great time to get involved, since with the advent of the upstart-monitor the fun expands to include GUI hackers too!! 😉

…read more
Source: FULL ARTICLE at Planet Ubuntu

Combining multiple files

By sandeepkmehra

I have 2 files.
each having 3 coloums
1st field date as 20130322
2nd field time as 05:55
3rd field numberic value

File 2 has entries missing for some date time.
FILE1
20130322 05:35 2219
20130322 05:40 1809
20130322 05:45 1617
20130322 05:50 1359
20130322 05:55 2233
20130322 06:00 1648
20130322 06:05 1552
FILE 2
20130322 05:35 170
20130322 05:40 169
20130322 05:45 172
20130322 05:50 171
20130322 06:05 176

I want to join these 2 files and put zeros for missing values
o/p should look like :
FILE1 FILE2
20130322 05:35 2219 170
20130322 05:40 1809 169
20130322 05:45 1617 172
20130322 05:50 1359 171
20130322 05:55 2233 0
20130322 06:00 1648 0
20130322 06:05 1552 176

Thanks in advance ..

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

NIM Restore hangs at the start

By elcounto

Hello Gurus,

I have a couple of questions, I’m trying to do a mksysb restore from backup and it has just hung at the start.

Code:

RS/6000 Firmware
Version TCP05287
(c) Copyright IBM Corp. 2000 All rights reserved.
-------------------------------------------------------------------------------
LOAD: Waiting 60 seconds for Spanning Tree
BOOTP R = 1 BOOTP S = 1
FILE: /tftpboot/bsrs6d
Load Addr=0x4000 Max Size=0xbfc000
FINAL Packet Count = 16105 Final File Size = 8245686 bytes.
-------------------------------------------------------------------------------
Welcome to AIX.
boot image timestamp: 11:10 11/28
The current time and date: 15:40:43 03/21/2013
number of processors: 1 size of memory: 1024Mb
boot device: /pci@80000000/ethernet@c:10.11.2.9,,10.11.2.88,10.11.0.1,00,00
closing stdin and stdout...
-------------------------------------------------------------------------------


Anyone know why this is happening and how I can break out of it without someone going to power off the machine from the front panel. I’m logged on through the console cable and not the HMC unfortunately.

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

sed text extraction between 2 paterns using variables

By radudownload

Hi everyone!

I’m writting a function in .bashrc to extract some text from a file. The file looks like this:
” random text
Begin CG step 1
random text
Begin CG step 2

Begin CG step 100
random text”

For a given number, let’s say 70, I want all the text between “Begin CG step 70” and “Begin CG step 71” to be saved in one file. I saw one can use sed for this, but I don’t know how to change the code in such a way that variables and sed work along. For the moment the code looks like this:

Code:

step()
{
# $1 step number
# $2 data file
STEP=$1
STER=$(($STEP + 1))
FILE=$2

sed -n "/Begin CG move = "{$STEP}"/,/Begin CG move = "{$STER}"/p" $FILE > step.$STEP.tmp


I also tried

Code:

sed -n '/Begin CG move = "$STEP"/,/Begin CG move = "$STER"/p' $FILE > step.$STEP.tmp


none of them write something usefull (in fact they don’t write anything)

Thank you!

r

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Need to split a string

By adshocker

Hi,

We have a SunOS 5.10 Generic_142900-13 sun4v sparc SUNW,T5240.

I’m trying to find a way to split a string into 2 variables.

Ex:
parm1=”192.168.1.101/parent/child”

What I need to do is split the string above into:

host=”192.168.1.101″
location=”parent/child”

I saw the solution provided here http://www.unix.com/shell-programmin…tion-file.html but somehow we don’t have the -o option for grep as I keep getting illegal option –o.

The purpose of this is for a shell script already created to do an FTP function. Originally it was intended for accepting HOST, USER, PASS and FILE parameters only. Basically file goes to whatever the main directory on FTP connect. Now users are passing HOST/folder as value for HOST parameter which gives out an error now since 192.168.1.101/parent/child is not a valid HOST. And it would be a lot of work to add another parameter for LOCATION because a lot of other programs are already using this script so I’m trying to avoid this solution for now.

I’d appreciate any suggestions.

Thanks.

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Execute all files at once

By Birda

Hi everyone, i’m newbie to unix!
If I have many files named by temp1.txt, temp2.text, temp3.txt,….. I want to introduce some key words at the top of each of files. The script (named bimbo) I tried is shown.
#!/bin/csh
set FILE=$1
echo $FILE
set OUT=$1
echo ‘%tage=’$FILE >> x_$FILE
sed -e ‘2i%aveg=330’ x_$FILE > x1
sed -e ‘3itemp=3000MB’ x1 > x2
sed -e ‘4i%rain=8’ x2 > x3
sed -e ‘5i@skyhigh’ x3 > x4
sed -e ‘6i ‘ x4> x5 # insert blank line
echo ‘topic:’$FILE.txt >> x5 # file names
sed -e ‘8i ‘ x5> x6
sed -e ‘9ibm nnm’ x6 > x7
cat x7 $FILE.txt > $OUT.out

when I execute: ./bimbo temp1 it works but not for multiple files at once /bimbo *.txt,? so how do i make to excetue all files at once? thanks

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Combining two files line by line

By johankor

Hello guys, I have a problem with two text files. I want to join them line by line with a bash script if it is possible. I think an example will be much clear;

Code:

FILE 1
314.01 83.826
52.43 79.544
316.36 45.283
351.15 87.503

FILE 2
140.323 84.918
130 78.256
120 77.603
118 79.047

I want the output like below:

OUTPUT
314.01 83.826
140.323 84.918
52.43 79.544
130 78.256
316.36 45.283
120 77.603
351.15 87.503
118 79.047


I hope it is clear with the example. Both of the files are more than 500 lines long so it is really much appreciated if you can find an easy solution.

Thanks

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Utilities not dying after script run

By Marc G

Hi folks,

Friendly router geek wanting to be a programmer here…

So I worked with another guy here and came up with this to capture Unix admin data:

Code:

#!/bin/ksh
#
#
# Set Default Paths
#
PATH=/usr/apps/client/bin:$PATH; export PATH
LD_LIBRARY_PATH=/usr/apps/client/lib:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH
NOSHOME=/usr/apps/client/bin; export NOSHOME

# Execute the NOS provided top program with CPU MEMORY and LOAD values to be extracted to temporary files
#
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep CPU | /usr/bin/awk -F"," '{print $1}' | /usr/bin/awk -F":" '{print $2}' | /usr/bin/awk -F" " '{print $1}' > /tmp/cpu.out
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep Memory | /usr/bin/awk -F"," '{print $1,$2}' | /usr/bin/awk -F":" '{print $2}' | /usr/bin/awk -F" " '{print $1","$4}' > /tmp/mem.out
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep Memory | /usr/bin/awk -F"," '{print $3,$4}' | /usr/bin/awk -F" " '{print $1","$4}' > /tmp/swap.out
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep load | /usr/bin/awk -F";" '{print $2}' | /usr/bin/awk -F":" '{print $2}' | /usr/bin/sed 's/^[ ]*//;s/[ ]*$//' > /tmp/loadavg.out

# Gather all data into single file and clean up
#
CPU=`cat /tmp/cpu.out`
MEM=`cat /tmp/mem.out`
SWAP=`cat /tmp/swap.out`
LOAD=`cat /tmp/loadavg.out`
HOST=`/usr/bin/hostname`
DAY=`/usr/bin/date +%b-%d-%y`
TIME=`/usr/bin/date +%H:%M:%S`

# Configure date values to figure out proper storage of comma delimited values
#
typeset -i MONTH=`/usr/bin/date +%m`
MONTH=$(echo "$MONTH" | tr ' ')
typeset -i DAY=`/usr/bin/date +%d`
DAY=$(echo "$DAY" | tr ' ')
typeset -i YEAR=`/usr/bin/date +%Y`
YEAR=$(echo "$YEAR" | tr ' ')

# Create a variable FILE to concat variables into a single variable to test against
FILE=$MONTH"-"$YEAR-$HOST".dat"

# Check to see if file is empty. If not, populate the values, otherwise create the needed file and populate
#
if [ -e $NOSHOME/../data/OSKPI/$FILE ]
then
echo $HOST","$DAY","$TIME","$CPU","$MEM","$SWAP","$LOAD >> $NOSHOME/../data/OSKPI/$MONTH-$YEAR-$HOST.dat
else
echo $HOST","$DAY","$TIME","$CPU","$MEM","$SWAP","$LOAD > $NOSHOME/../data/OSKPI/$MONTH-$YEAR-$HOST.dat
fi

# Remove all temporary files and exit
#
rm /tmp/cpu.out /tmp/mem.out /tmp/swap.out /tmp/loadavg.out
exit 0


But once the script runs, it leaves processes still running as shown:

Code:

bash-3.00$ ps -efa | grep -v wrapper | grep -v oracle | grep -v java
.
.

.
root 11153 11098 0 07:00:04 ? 0:00 /usr/bin/sed s/^[ ]*//;s/[ ]*$//
root 19606 479 0 00:14:49 ? 0:00 /usr/lib/ssh/sshd
<font ...read more
Source: FULL ARTICLE at The UNIX and Linux Forums