Programming :: Bash Script: Check Stderr After Command "find"?
Jul 8, 2009
I use command "find" in my bash script: if the filename exist command find work quiet, and if the filename not exist I see the message "find: /tmp/filename: No such file or directory". My problem is following, i want to have in my script something like this:
find "/tmp/filename" -type f -delete | "if no_any_errors execute command1" , if file_not_found execute command2"
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
I wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.
perl -pi -e "s/$findstring/$replacestring/" testfile where as $findstring = print F_WC_TMP"$line "; and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line ";
But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.
So I want to run command through ssh but also run a if check in bash to see ifa file exist. I know that to run ssh commands you do ssh user@server YOURCOMMANDbut if i need to run an if statements, how would this work??
I want to output the stdout and stderr in a logfile,moreover i do want to log stderr also to a separate logfile, and print str to the screen I searched arround and tried:
Code:
$ command 2>&1 > log | tee -a log log.err
But then in log first the stdout appears, and then stderr.
I'm having trouble trying to make a script. What I want to do is check if xScreenSaver is running in my user account. If not, run it. If it's running, kill it.
So this is the script I've made:
Code:
The problem is that I've echoed the output of $(pgrep -u $(whoami) xscreensaver) and it always seems to add 4 numbers to the pid, even if the pid doesn't exist. What do I mean by "doesn't exist"? That no xscreensaver is running in my user, and if I run pgrep -u $(whoami) xscreensaver in bash, I get not output, but if I run the command though the script, I get (for instance) 4050. If I run it again, I get 4054, and again 4058... etc. What the hell is going on with that?
I am looking for a little help with a Bash Script. I have just finished a PC GUI application using Pygtk and glade. But, I would like to write a Bash Script to check if the user has the needed software to run my application on his or her computer. For example, the software needed to run my application among others are Python, nmap, and pygtk. Code: which python which nmap With a little bit of research I found:If python or nmap are installed on my computer and I run the above commands, the above code will tell me where it is located. But if python and nmap are not installed and I run the commands, nothing is displayed.
Could I get a few ideas on how I would go about getting a boolean value to determine whether or not the software is installed or not. I would like to use the boolean value in my bash script to perform other actions ie echo "Python is not installed" or actually install Python if the boolean value is false.
This script that I found online does the job it promises. it does convert the files to mp3 without an issue. What I need to include now is an if statement that says If $file.mp3 exists then delete $file.wav
Code: #!/bin/sh # name of this script: wav2mp3.sh # wav to mp3 # Credit to the script creator (Nikesh Jauhari):
[Code]...
After that I'm stumped as to how to do the if statement
I've just installed java (jre-6u21-linux-i586.bin) on Red Hat 4.4 AS and issued this command to check the java version: java -versionand got :bash :java: command not found
I'm creating a bash script to check how much free space is left in /var directory then, if it hits a certain threshold, delete certain files with numbers for extensions (e.g. fileA.1, fileA.2 fileA.3, and fileA.4, fileB.1, fileB.2 fileB.3, and fileB.4 ). Here's a snippet from my script:
[Code]...
If I use a * as a wildcard for the number extension, the script fails. Maybe regex would work here, but I'm not particularly accomplished at it. Or some other construct.
I have been searching for 90 minutes for something that I "think" should be fairly easy. I'm pretty new to Bash Scripting so I could be completely wrong. Then again it may be a weird request to even need something like this. But here it is.I have a script written to convert data from one of our software version to another. The only thing I need to add to it is a "check to make sure the user running the script is in the /tmp directory".
I'm building a script for my place of employment. The next step in it is checking what the user input was. Determining if they added a part in there or not. The script prompts for a hostname. Hostnames are localhost.localdomain. Now, I want the script to check to see if they put localdomain and if they did, not to add the domain to the /etc/sysconfig/network, but just what they entered. So say the user inputs:
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.
I have a little complex Makefile system. A parent Makefile call dozens of Makefiles in subdirctories. And the subdirctory Makefile calles shell script to do real building. I want to grab all output this Makefile system generate. So, i employ "make 2>&1 > make.log". but not all output messages are filed into make.log. The message generated by sub-makefile called shell script cannot be recorded into make.log. And another curiouse thing is, if i launch "make 2>&1 > make.log" in a perl script, all output do be sent into make.log.
I'm having problems with Tomboy. I have a few hundred note files and I need to go through all of them and replace all instances of "<link:broken>a</link:broken>" with "a". Is there a bash command I can use to do this?
Im looking for assistance to create a script to find and replace files.Probably best if I give you the background Our server uses a specific application which stores user data, each user data account (a folder on the server) has a file called 'Profile.xml' this file gets updated and replaced about every 30 mins similar to the fashion logrotate works i.e. Profile.xml.1 Profile.xml.2 -> .10
What we experience is that if the application crashes unexpectedly while it is doing its user profile refresh task we end up with sometimes a few hundred Profile.xml files which end up 0kb(should be around 4kb) , and our server see's these as corrupted profiles and will not see them. Our fix is to go back thru and rename the Profile.xml.1 to be Profile.xml (or sometimes up to Profile.xml.5 to Profile.xml) We want a script we can manually run to automate this process The server tree is
I am trying to find a nightly backup if it was successfully copied over, rename it and curl, but it's always passing the check even if the file is older than specified. From the command line it does as it should. Example is here;
Code: find /backup -type f -mmin +4440 -exec echo "found" {} ; - nothing returned (good). Then I change the time
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 ?
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".
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.
i had a problem with the find command in bash (which i deem is close enough to a promming language, if not please move this thread :P). i tried to reduce the command to the problem. i want the backticks, or $() for that matter; to be evaluated by -exec of find, not by bash. is that a caveat of find?
Code:
$ find testd -exec echo `basename {}` ; #confused me test test/a test/b
[code]...
edit: i found out whats causing this. `basename {}` gets evaluated by bash before find is invoked, returns {} and `find . -exec echo {} ;" is run. now my question is, how to escape this eveluation from happening before.