Programming :: Using The Process Status (ps) Command In A Bash Script?
May 27, 2009
I am new to scripting and been working on this bash script for awhile now. I been researching this problem, but I can't seem to find a solution. I was wondering if someone could please help me out. Here is my script:
#!/bin/bash
NO="ps -ef | grep NO | grep -v grep"
NOWC=`ps -ef | grep NO | grep -v grep | wc -l`
[code].....
I cannot get this script to run the "ps -ef" command on the client. It get its value from the host machine that I am running this script from. I need this command to execute on the client. When I run the command (ps -ef | grep NO | grep -v grep) on the client, I get something back. Here is what I get when I try to debug the script.
XX# ./test_ps5.sh XXXXX
+ NO='ps -ef | grep NO | grep -v grep'
++ ps -ef
[code]....
View 5 Replies
ADVERTISEMENT
May 25, 2010
How can I programatically know the status of a process if its PID is known?
View 1 Replies
View Related
Mar 22, 2011
I am going to create a parent process and fork a child process from it. I want to write a code in such a way that whenever my child process end it must indicate that the child process is terminated by a signal or not. This code must be written in the parent process block.
View 6 Replies
View Related
Jun 10, 2010
I am running a command pretty similar to the one below:
Code:
I need to capture the exit status of that part of the command.
What I am trying to do is set a variable that can be modified within my_job.sh, and used to exit.
However, no matter what I set "status" to in my_job.sh, it exits with "0".
What can I do differently?
View 3 Replies
View Related
Mar 3, 2010
How exactly can I use the exit status of a command in an if statement ?
Something like this:
Code:
View 3 Replies
View Related
Aug 7, 2009
I need to make a SQL script and call it from Unix (bash) shell.
Code:
sqlplus vikas/vikas <<END
spool /oracle/vikas/output.txt
command 1
[code]....
This runs perfectly, but my problem is that if a command fails, the other commands keeps on running. I need to keep a check that when a command fails the script is exited. In unix we have an option of echo $? to check the status of previous command, But how to accomplish this SQL.
View 2 Replies
View Related
Nov 25, 2010
file allids consists of 300,000 rows, each containing a 5-7 digit numeric id. file newids consists of 20,000 rows of id's. How do you explain the following timings? time: 0.07s:
Code:
diff <(sort allids) <(sort newids)
time: 1.6s:
[code].....
View 4 Replies
View Related
Apr 1, 2010
pretty simple. how would you background a process from a script and get its process id at the same time?
View 6 Replies
View Related
Mar 14, 2010
Further to solved LQ thread Bash: how to populate a list of arbitrarily named files?, what is the functional difference between feeding a loop with process substitution and feeding it with a here string with embedded command substitution? ABSG pages: process substitution, here string and command substitution. This works
Code:
while IFS= read -r -d '' file
do
files+=("$file")
done < <(find $dir -type f -print0)
[code]....
View 2 Replies
View Related
Nov 14, 2010
My server pretty often becomes full up php processes running which are not needed. Is there a way to search for and kill any php process that is more than 3 hours old?
View 7 Replies
View Related
Nov 15, 2010
My server pretty often becomes full up php processes running which are not needed.Is there a way to search for and kill any php process that is more than 3 hours old? as I understand it, i need to use ps piped with awk. awk at the moment seems very complicated to me, do not how to start tackling it.
View 5 Replies
View Related
Jul 14, 2011
Distro: Centos 5, PHP 5I have done a bit research on running bash commands from php and there was little success. This is my relevant php script
<?php
echo exec('pwd');
?>
[code]...
View 16 Replies
View Related
Mar 9, 2011
I am trying to grep multiple numbers from file, grep does have the -f option for that.
Code: grep -f <`seq 500 520` /etc/passwd I know this could be done with
Code: for i in `seq 500 520`; do grep "$i" /etc/passwd; done But my question is fare more behind this example. It is possible to redirect one command output which will be treat as a content of file for another command ?
View 2 Replies
View Related
Aug 11, 2010
I understand that $! is the PID of a command. For example:
Code: #!/bin/bash
myprogram &
echo "PID of myprogram is $!"
I'd like to send the output of "myprogram" to both console and to a log file using the "tee" command but I also want to store the PID of "myprogam". Something like this:
Code: #!/bin/bash
myprogram | tee ./logfile &
echo "PID of myprogram is $!"
The problem is that $! is now the PID of "tee" rather than the PID of "myprogram".
View 3 Replies
View Related
Mar 24, 2011
I often want to extract some info using awk from a variable/filename while running other things using xargs and sh. Below is an example:
Code: ls -1 *.txt | xargs -i sh -c 'NEW=`echo $0 | awk -F'_' '{print $1}'`; echo $NEW' {}
In the above case I would like to grab just the first field from a filename (delimited by '_') from within an sh command. This is a simplified example, where normally I would be doing some further data processing with the sh command(s).
The error message that I get is:
Code: }`; echo $NEW: -c: line 0: unexpected EOF while looking for matching ``'
}`; echo $NEW: -c: line 1: syntax error: unexpected end of file.
I haven't been able to figure out how to escape the awk command properly.
View 1 Replies
View Related
Sep 29, 2010
I have the following command that works Code: ssh root{at}IPADDRESS 'vim-cmd vmsvc/power.getstate 64 | grep Powered | awk "{ print $2}"' Which outputs the following text:- Powered on I would like to Append some text so the output is:- Ubuntu Server: Powered on Every different variation that I have tried ends up in an unexpected token.
View 1 Replies
View Related
Mar 24, 2011
I am trying to process a column separated data file, with a few bash command. For example, I have
Code:
file1 aaaa yes
file2 aaaa no
file3 bbbb yes
Let say I want to create new file with the output of first column and do something else with the output of 3rd column. Of course there are many ways to process this data file, but I wish to know by using awk, how could I do it. I'm trying:
Code:
awk '{system("touch $1")}' datafile
but the shell command will not able to get the awk '$1' output. How do I get this done ? And for another question, if the data file contains the variable name of a shell variable, how could I make use of it during a awk output ? For example I have a datafile1:
Code:
server1 yes
server2 no
And in another server declaration data file, I got this datafile2:
Code:
server1=xxx1
server2=yyy1
And in my awk script, I want to achieve something like (the syntax is definitely wrong, just to demonstrate what I assume it will like):
[code]....
View 12 Replies
View Related
Jan 20, 2011
As part of my script I need to compress a 50Gb file. but I need to check that the compressed is not corrupt if it is ok it will then send it over if not it will report an error.
cd /home/ops/Desktop/temp
tar czvf backup-"$(date +%d-%b-%y)".tgz /home/ops/Desktop/temp
I need some here to check the compress file then somelike if the file is
if
send the file
else
send an e-mail reporting a failure
View 4 Replies
View Related
Mar 1, 2011
I am having all sorts of trouble trying to assign a variable within an awk script with the system command. I know there is a lot of ways around this problem, but for efficiency reasons, I would like to, within my awk script, do something like
system(x=3)
or
system(x=NR)
and, latter on the shell script which calls the awk script, use the variable $x. But nothing is passed to x. I have already tried things like
command = "x=3"
system(command)
and also used a pipeline within the system to pipe it to /bin/sh In fact tried a lot of stuff like that, using $(( )) etc etc etc I can create directories e write to files (yes, i could write to a file and read from there, but I dont think it is efficient, plus I am puzzled).
View 7 Replies
View Related
May 15, 2011
I want to write a bash script that will launch a command when ever I plug my phone in. how would I monitor the port in a script.
View 2 Replies
View Related
Apr 6, 2011
I'm trying to do something here:: I'm writing a bash script, I want to [open a new terminal and run a bash command in it] inside the script. I tried to use this, but apparently I get syntax errors.
Quote:
#! /bin/bash
echo "echo Something" > ~/Second.sh
chmod +x ~/Second.sh
xterm -e sh -c ./Second.sh
View 14 Replies
View Related
Jul 8, 2011
Bash 3.1.7
Suppose this bash script:
Code:
#!/bin/bash
ls foo
I would like the output to be
Code:
ls foo
foo
That is, the command is first echoed then executed. Is it possible to do this? Or is the only way to debug the script?
View 2 Replies
View Related
Sep 12, 2010
Is it possible to organize bash script output of which is like on top command i.e. monitoring every let's say 1 sec and old information would cleared?
View 3 Replies
View Related
Jul 11, 2010
This pretend to be a script for rename a lot of files automatically. So I put the list of files in an array named @lista. But, as you can see, at the end of the command I use a sed filter to print out a backslash for those files that have spaces in their names, so the path for those files could be rightly interpreted.
But there's no way I could print a backslash. It works well when I use the Perl's sed substitution s///, but I need every path in the array to be fixed.
I'd like to add that the bash command works perfectly well alone. I mean outside the Perl script.
This is de command line with the sed filter:
Code:
And this is what it brings:
Code:
View 12 Replies
View Related
Oct 19, 2010
I want to delete all files within a specific folder without actually deleting the folder, what is a good bash command for this?. I found this one but encountered some errors even though I am executing it within the specific folder:
useratdebian:/home/user/folder# find . -type f -exec rm -rf {} ;
[1] 5052
useratdebian:/home/user/folder# find: missing argument to `-exec'
[1]+ Exit 1 find . -type f -exec rm -rf
The command as it appears is:
find . -type f -exec rm -rf {} ;
how to delete only the files contained within the folder called "folder" for example?
View 4 Replies
View Related
Jul 16, 2010
I'm writing a Bash script to take IPTC keywords from a text file and write them, via Exiv2, to several (first batch is 100) JPEG files in a single directory. The script has one while loop inside another while loop, both terminated, but I'm pretty sure that's not my problem. I think it's how I'm incrementing the "counter" variable, although it could also be the method of parsing the text lines from the file (using cut with delimiters that have worked fine in simpler scripts).
Here's the code as I've worked it up to this point.
Code:
And yes, "keywords" checks out in Crimson Editor, Emacs GUI and nano as an ASCII file with UNIX line endings. No issues on that score.
Feeding each line consecutively into a terminal (excepting the exiv2 command) works fine: each variable echoes with the part of the text line used as a variable value as it should, even when the b variable is incremented the quick&dirty way (up arrow three commands and hit enter).
Running the above script in eval mode (sh -x) stalls after setting the b variable to one and reading in the first line of text. I'd like to know why. I'd also like some advice on another reliable method of parsing the read-in lines.
View 14 Replies
View Related
Feb 12, 2011
I'm trying to execute the following command within a bash script:
Code:
tac /var/log/system.log | head -1
The script I wrote is:
[code]...
View 1 Replies
View Related
Feb 16, 2011
Writing script to create backup of file by adding datetime to file name. Basically test for file presence if there, cp with datetime then rm original cp works fine from command line but get cannot stat `full path to file': No such file or directory
Code:
Here are the errors: cp: cannot stat `~/html/CVP_dadamail/.dada_files/.logs/errors.txt': No such file or directory rm: cannot remove `...': No such file or directory
The for statement is a placeholder as I have same file to backup out of several directories. using "bash -x scriptname" -OR- inserting echos, I can see I've constructed the strings properly. Believing it might be related to the hidden directories, I tried setting the shopt "glob" options to no avail.
Ultimately I'll add the other directories to the for loop and then run this from a cron job, so if you see potential pitfalls knowing I'm headed in that direction...believe construct would be
Code:
View 4 Replies
View Related
Jan 26, 2011
I have a command that outputs n lines of text, and I want to place each line into an array element, but I can't seem to get the syntax correct
So my command is this:
cat $configfile | sed -n '/cluster:'$clustername'/,/cluster/ p' | awk /host/
Which produces many lines depending on the value of $clustername. I'd like to get each line as elements of an array.
View 5 Replies
View Related
Mar 22, 2010
I'm trying to write a bash script program in the Linux command terminal that will write to a fellow user and then continue reading down the program. this is what i have (kind of explains the idea too):
#!/bin/sh
clear
echo "this is before the write command"
write jcummins
this message should go to jerry
echo "the message didn't send and this string will not appear"
echo "it appears it has stopped at the write command"
View 5 Replies
View Related