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"

View 1 Replies


ADVERTISEMENT

Programming :: Command In Bash Script To Check If Tar Is Currupt Or Not?

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

Programming :: Find And Replace A String In A File Using Perl Command From Bash Script?

Feb 14, 2011

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.

View 5 Replies View Related

General :: Run Command Through Ssh But Also Run A If Check In Bash To See Ifa File Exist?

Aug 1, 2011

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??

View 4 Replies View Related

Software :: Bash Output Stderr To 2 Files And Stdout?

Apr 5, 2011

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.

View 1 Replies View Related

Software :: Qt Creater 4 - C++ & Stderr - Use QDebug() To Print Out Stderr Messages?

Jul 27, 2010

Can I use qDebug() to print out stderr messages? If I just use qDebug() << stderr; I get hex output.

View 1 Replies View Related

Programming :: BASH - Can't Check If XScreenSaver Is Running

Feb 26, 2011

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?

View 5 Replies View Related

Programming :: Bash Function Check For Valid IP?

Apr 16, 2010

I have been working on this way too long now...this *should* be simple. I must be missing something simple at this point.

Code:
function f_is_ip()
{
if [ "`echo "$1" | /bin/egrep "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}"`" != "" ] ## Error on this line

[Code]....

When I echo $1 ## prints 192.168.1.22

View 4 Replies View Related

Programming :: BASH - Script To Check Installed Software?

Apr 1, 2011

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.

View 3 Replies View Related

Programming :: Bash - Statement To Check If A File Exists Or Not?

Oct 6, 2010

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

View 14 Replies View Related

Programming :: Bash Script To Check How Many Files In Directory?

Jan 31, 2009

i was wondering if there's a bash script to check the amount of files in a directory with an IF statement..

View 8 Replies View Related

General :: Command To Check The Java Version: Java -versionand Got :bash :java: Command Not Found?

Jul 26, 2010

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

View 4 Replies View Related

Programming :: Bash Script To Check How Much Free Space Is Left In /var Directory

Feb 24, 2011

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.

View 18 Replies View Related

Programming :: Check If The User Is In Correct Directory Before Executing Bash Script

Dec 10, 2010

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".

View 7 Replies View Related

Software :: Bash Command To Find Out If User Exists?

Jan 20, 2011

Is there any linux command to find out if a user exists? It should something like this: if user exists it returns 1, if he doesn't it returns 0.

View 3 Replies View Related

Software :: Use The Output Of The Find Command In The Bash Script?

Nov 17, 2010

I'm fairly new to writing bash scripts and haven't been able to find a an example of effectively using a the find command in a bash script.

I want to run some git commands on any sub directory that has a .git project in it. Getting to the directory is not my problem, its how to find them

What i want to do is execute

Code:
find -name .git

Then act on each response line that is printed out. E.G Navigate to the directory and run git status.

How do i use the output of the find command in the bash script?

View 6 Replies View Related

Programming :: Check Command Line For A Word?

May 23, 2010

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:

[Code]....

View 4 Replies View Related

Programming :: SQL Script To Check Status Of Last Command?

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

Programming :: Cannot Redirect All Stdout And Stderr Into File

May 12, 2009

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.

View 2 Replies View Related

Fedora Installation :: Bash Shell Could Not Find Kfontview Command

Apr 5, 2009

Bash shell could not find "kfontview" command, although kdebase-4.2.1-2.fc10.i386 already installed?

View 2 Replies View Related

General :: Bash - Command To Find Files Changed In Last N Seconds?

Jun 21, 2011

Linux command to find files changed in last n seconds. shell script,that we can run from cli or command.

View 3 Replies View Related

Ubuntu :: Bash Command To Find And Replace Text In File

Apr 3, 2010

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?

View 2 Replies View Related

Programming :: Bash Command From PHP?

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

Programming :: Find And Replace Script In Bash?

Sep 28, 2010

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

/mnt/array1/username/db/Profile.xml
/mnt/array2/username/db/Profile.xml
etc
etc

What we have so far is a script which finds the affected files

find /mnt/ -maxdepth 4 -name Profile.xml -size -1k

This will display a list of affected profiles, and we can append it to a text file with >>output.txt on the end.

if 'pattern' in 'location' equals '0kb' then 'cp' Profile.xml.1 Profile.xml

View 4 Replies View Related

Programming :: Bash Find Files On Time Help?

Mar 11, 2011

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

[code].....

View 4 Replies View Related

Programming :: Bash Ambiguous Redirect - Redirect One Command Output Which Will Be Treat As A Content Of File For Another Command?

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

Programming :: BASH: Get PID Of First Command In Pipe

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

Programming :: Using AWK Within Bash Command Via Xargs

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

Programming :: `find . -exec' Handling Backticks In Bash

May 15, 2011

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.

View 11 Replies View Related

Programming :: Find Out If X11 Is Running From Within Perl OR Bash Script?

Mar 17, 2010

I am writing a script based image manipulator but i need to know if X is running so i can tell if i use CACAVIEW to imagemagick DISPLAY command.

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved