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


ADVERTISEMENT

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

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

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 :: 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 :: 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 :: Bash: Remote SSH Command Append To AWK?

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

Programming :: Using Bash Command To Execute Output Of Awk?

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

Programming :: /usr/bin/expect : Script To Check Server Load Using Both Expect And Bash?

Jul 27, 2010

I am trying to make a script that can be used to check server load on a remote server and produces sound on our local machine, when server load exceeds a particular limit.1. I want to execute command uptime or uptime | awk '{print$10}'on the remote server and store the result in a variable(say x), and later use it in the bash script.

Bash Part
#!/bin/bash
x=$(/root/Desktop/exp)

[code]...

View 1 Replies View Related

Programming :: Assigning Bash Variable With The System Command In Awk?

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

Programming :: Write A Bash Script That Will Launch A Command?

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

Programming :: Run A Command On A Separate Terminal In A Bash Script?

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

Programming :: Echoing A Command Line Within A Bash Script?

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

Programming :: Organize Bash Script Output Of Which Is Like On Top Command

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

Programming :: Sed Bash Command - Not Print Backslash In Perl

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

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 View Related

Programming :: Bash Command To Remove All Files Within A Specific Folder?

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

Programming :: BASH - Works On The Command Line, Hangs As A Script?

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

Programming :: Bash Script: Assign Command Ouput To A Variable Without Executing It?

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







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