bash

How do I echo $command without breaking the layout

Hi. I'm trying to do the following in a bash script: com=`ssh host "ls -lh" ` echo $com It works, but the echo will break the output (instead of getting all lines in a column, I get them all in a row). If I do: ssh host ls -lh in the CLI it will give me the correct output + layout. Any ideas? ...

SED, using variables and in with an array

What I am trying to do is run the sed on multiple files in the directory Server_Upload, using variables: AB${count} Corresponds, to some variables I made that look like: echo " AB1 = 2010-10-09Three " echo " AB2 = 2009-3-09Foo " echo " AB3 = Bar " And these correspond to each line which contains a word in master.ta, that n...

How to Grab MAC Address of Active Ethernet Connection in Bash Script?

Simple Question: How do I grab the MAC address of the active Ethernet connection in a bash script? I currently have: set - `/sbin/ifconfig eth0 | head -1` MAC=$5 Which outputs the MAC address of the eth0, but if it's eth1 that's active, I want that instead. Could I beforehand execute ifconfig | grep inet but that wouldn't tell me w...

AWK: how to read columnwise file to AWK-script in Bash?

$ cat read.sh #!bin/bash // how can I read the columnwise data to awk-script? awk '{sum+=$1} END {print sum}' read $ cat data 1 2 3 4 5 $ . ./read.sh <data awk: cmd. line:1: fatal: cannot open file `read' for reading (No such file or directory) ...

Detecting when a process has finished (but not exited)

I have a program that's run in unix (that I have no control over) that when finished prints 'Completed successfully' but does not exit. I want to automatically detect when the process finishes (by checking the output of the command), so that I can kill the process and so that I can proceed do other activities. The complexity comes becaus...

Compatibility of x-www-browser

I want to open html files from a shell script. I know that Ubuntu has a command x-www-browser that will open the default browser on the system. I also found via some Googling that the command is part of the debian system. I was wondering if the command is available on non debian based distros. If it isn't is there a standard way of openi...

Use the output of a command as input of the next command

So I call this PHP script from the command line: /usr/bin/php /var/www/bims/index.php "projects/output" and its output is: file1 file2 file3 What I would like to do is get this output and feed to the "rm" command but I think im not doing it right: /usr/bin/php /var/www/bims/index.php "projects/output" | rm My goal is to delete ...

SVN: and bash: How to tell if there are uncommitted changes

I'm trying to wrap a standard sequence of steps in a shell script (linux/bash) and can't seem to figure out how to tell if the execution of svn status returned anything. For example ~/sandbox/$svn status ? pat/foo ~/sandbox/$echo $? 0 If I delete the foo file, then the svn status return nothing, but the echo $? is still 0 I ...

boolean type for while loop in bash?

I have a cron script on a shared web host that occasionally gets killed. I'd like to make a loop in bash that tries again if it gets killed, because most of the time it will make it. I'm having trouble with the syntax for storing a boolean value :P #!/bin/bash VAR=0; while [ $VAR ]; do if nice -19 mysqldump -uuser -ppassword -h dat...

Fork two processes and kill the second when the first is done

...

BASH Expression to replace beginning and ending of a string in one operation?

Here's a simple problem that's been bugging me for some time. I often find I have a number of input files in some directory, and I want to construct output file names by replacing beginning and ending portions. For example, given this: source/foo.c source/bar.c source/foo_bar.c I often end up writing BASH expressions like: for f in s...

Intersection of two lists in Bash

I'm trying to write a simple script that will list the contents found in two lists. To simplify, let's use ls as an example. Imagine "one" and "two" are directories. one=`ls one` two=`ls two` intersection $one $two I'm still quite green in bash, so feel free to correct how I am doing this. I just need some command that will print ...

More efficient way to find & tar millions of files

I've got a job running on my server at the command line prompt for a two days now: find data/ -name filepattern-*2009* -exec tar uf 2009.tar {} ; It is taking forever, and then some. Yes, there are millions of files in the target directory. (Each file is a measly 8 bytes in a well hashed directory structure.) But just running... ...

How do I call internal function in bash if I have defined with the same name?

I want to overload the functionality of cd in bash so that I can do the following checks: if the directory is not in DIRSTACK -> pushd dir else cd dir (or cd ~#) However now I get a recursive loop when trying to cd The reason for this is that I am trying to work around the fact that bash does not support set dunique ...

List files that don't match a string in bash

Dear all, I'm a newbie in bash and I would like to pass as parameter to a python function all files in a directory that don't match a given pattern. sth. like: $myscripts/myprog.py $myfiles/!(bonjovi) The above example should retrieve all files that don't match to "bonjovi". Best wishes ...

Making archive from files with same names in different directories

Hi, I have some files with same names but under different directories. For example, path1/filea, path1/fileb, path2/filea, path2/fileb,.... What is the best way to make the files into an archive? Under these directories, there are many other files under these directories that I don't want to make into the archive. Off the top of my he...

find files matching either some string or some other string in bash

I wonder how to specify to the command find for searching files with names matching some string or some other string. For example, if I want to look for files that match either *dat or *txt under current directory, how to specify? Thanks and regards! ...

"find" files under current directory but skipping some specific sub-directories

I wonder how to specify to the command "find" for searching files under current directory but skipping some specific sub-directories. For example, I would like to skip sub-directories that match "./dir1/*.1/" Thanks and regards! EDIT: Thanks for your help! It works with -prune. If I would like to exclude subdirectories that match...

Replace delimited block of text in file with the contents of another file

I need to write a simple script to replace a block of text in a configuration file with the contents of another file. Let's assume with have the following simplified files: server.xml <?xml version='1.0' encoding='UTF-8'?> <Server port="8005" shutdown="SHUTDOWN"> <Service name="Catalina"> <Connector port="80" protocol="HTTP/1.1"...

List and Remove directories in an archive

I wonder how to list the content in an archive file and remove some directories from it? For example, I have an archive file data.tar. I would like to list its content without extracting it. Is it possible to control the level of directory for viewing? I mean not necessarily every files, but just down to some level of the path. I al...