bash

AWK: Are these statements required?

Hi I have the following line in a Nagios bash script. It is being used to get the up and down error rates for the specified network cards: if=`awk -v interface="$INTERFACE" '$1 ~ "^" interface ":" { split($0, a, /: */); $0 = a[2]; print $3 " " $11 }' /proc/net/dev` I've never worked with awk before today, so I'm finding my way a bit....

Why are scripting languages (e.g. Perl, Python, Ruby) not suitable as shell languages?

What are the differences between shell languages like bash, zsh, fish and the scripting languages above that makes them more suitable for the shell? When using the command line the shell languages seem to be much easier. It feels for me much smoother to use bash for example than to use the shell profile in ipython, despite reports to th...

Ftp command to remove bunch of files

I can download files using wget "ftp://user:pass@host/prefix*, but I cannot remove downloaded files from FTP. Any easy solution to do this in bash script? ...

Simple bash problem related to executing command after previous has stopped (I am not programmer)

#!/bin/sh xmodmap -e "keycode 49 = equal plus" cd /media/5F53-7973/BGTrilogy/ wine ./bgmain.exe xmodmap -e "keycode 49 = dead_caron dead_tilde dead_caron dead_tilde notsign notsign" Basically what I want from it is that the last entry would only run after I quit wine ./bgmain.exe. What's the most foolproof way to do it? ...

Overrible predefined Bash variables with arguments

Can someone point me out what is the problem when I want to overrible a default value in a variable with an argument in Bash? The following code doesn't work: #!/bin/bash VARIABLE1="defaultvalue1" VARIABLE2="defaultvalue2" # Check for first argument, if found, overrides VARIABLE1 if [ -n $1 ]; then VARIABLE1=$1 fi # Check for seco...

BASH script - How to get bash to check for the location of a file?

Hi I want my bash script to find where php is installed - this will be used on different linux servers, and some of them won't be able to use the which command. Anyway I need help with that second line: #!/bin/bash if (php is located in /usr/bin/php); then PHP = /usr/bin/php else PHP = /usr/local/zend/bin/php fi $PHP script.php ...

strange wget behavior bash script

I created a script to download some iso files. This is the script: #!/bin/bash lynx -dump http://www.mydownloadsite.com/Downloads.htm | egrep -o http://www.mydownloadsite.com/images/iso_.*[A-Z].iso | xargs -n1 wget -d -P ~/Downloads/ISO/ -U Everytime i run this script wget starts downloading the first iso but hangs after downloading ...

Bash scripts handled differently then typing in the terminal?

I'm having some problems with bash scripting. I want the script to find the "Firefox.app" directory, but things that work when I type them in the shell interpreter don't work in the script. ffxapp=`find /Applications/ -name "Firefox.app" -print | tee firefox.location` When I type that into the shell, it works ($ffxapp == "/Application...

bash script to extract ALL matches of a regex pattern

I found this but it assumes the words are space separated. result="abcdefADDNAME25abcdefgHELLOabcdefgADDNAME25abcdefgHELLOabcdefg" for word in $result do if echo $word | grep -qi '(ADDNAME\d\d.*HELLO)' then match="$match $word" fi done POST EDITED Re-naming for clarity: data="abcdefADDNAME25abcdefgHELLOabcdefgAD...

Copy files from one directory into an existing directory

In bash I need to do this: take all files in a directory copy them into an existing directory How do I do this? I tried cp -r t1 t2 (both t1 and t2 are existing directories, t1 has files in it) but it created a directory called t1 inside t2, I don't want that, I need the files in t1 to go directly inside t2. How do I do this? ...

split text file in two using bash script

I have a text file with a marker somewhere in the middle: one two three blah-blah *MARKER* blah-blah four five six ... I just need to split this file in two files, first containing everything before MARKER, and second one containing everything after MARKER. It seems it can be done in one line with awk or sed, I just can't figure out h...

keeping home directories synchronized on to Linux Boxes

I have two servers, computer A and computer B, both running Linux. I need to write a program or a shell script which will continuously monitor the contents of my home directory on computer A and if anything changes, copy the changes to my home directory on computer B such that both home directories are always the same. (Any changes made ...

Bash script - Take system output and use it as a variable

Hi, Pretty simple question, I'm trying to get some output after executing a command and use it again. #!/bin/bash echo what's the source db name? read SOURCE echo what's the target db name? read TARGET db2 backup db $SOURCE online compress include logs READ SOME OF THIS LINE = SOURCE db2 restore database $SOURCE taken at $DB2TIME into ...

How to get unique `uid`?

I'm making a bash script which should create an ftp user. ftpasswd --passwd --file=/usr/local/etc/ftpd/passwd --name=$USER --uid=[xxx] --home=/media/part1/ftp/users/$USER --shell=/bin/false The only supplied argument to script is user name. But ftpasswd also requires uid. How do I get this number? Is there an easy way to scan pas...

uncompressing a large number of files on the fly

i have a script that i need to run on a large number of files with the extension *.tar.gz. what i want to do is instead of uncompressing them and then running the script, i want to be able to uncompress them as i run the command and then work on the uncompressed folder, all with a single command. i think a pipe is a good solution for t...

Substitute output from variable to give another output.

I am trying to substitute output from variable to give another output. The variable i have problems with is the $apps. It gives me "syntax error: bad substitution". $appletDir is a directory with desktop shortcuts. The problem is that some shortcuts do not have the same name as the icon(png). So i need to substitute the program name wi...

tar: add all files and directories in current directory INCLUDING .svn and so on

Hi all, I try to tar.gz a directory and use tar -czf workspace.tar.gz * The resulting tar includes .svn directories in subdirs but NOT in the current directory (as * gets expanded to only 'visible' files before it is passed to tar I tried to tar -czf workspace.tar.gz . instead but then I am getting an error because '.' has changed...

ping a server thru a specific port (fsockopen) in php

function checkServer($domain, $port=80) { global $checkTimeout, $testServer; $status = 0; $starttime = microtime(true); $file = @fsockopen ($domain, $port, $errno, $errstr, $checkTimeout); $stoptime = microtime(true); if($file) { fclose($file); $status = ($stoptime - $starttime) * 1000; $status = floor($status); } else...

Splitting a binary file on binary delimiter?

I'm working on a shell script to convert MPO stereographic 3D images into standard JPEG images. A MPO file is just two JPEG images, concatenated together. As such, you can split out the JPEG files by finding the byte offset of the second JPEG's magic number header (0xFFD8FFE1). I've done this manually using hexdump/xxd, grep, head, and ...

Bash: echo string that starts with "-"

VAR="-e xyz" echo $VAR This prints "xyz", for some reason. I don't seem to be able to find a way to get a string to start with -e. What is going on here? ...