shell-scripting

How can I restart JBoss 5.1 on AIX from a shell script?

I need to restart JBoss from my script? I tried to call jboss-5.1.0.GA\bin\shutdown.bat and then jboss-5.1.0.GA\bin\run.sh But unfortunately shutdown.bat works asynchronously. Is it possible to restart JBoss from shell script? ...

How to use grep to find all files that contain one pattern but don't have a second?

Is there an easy way using grep (or combine with other standard command line tools) to get a list of all files which contain one pattern yet don't have a second pattern? In my specific case I want a list of all files that contain the pattern: override.*commitProperties yet don't contain: super.commitProperties I'm on Windows but u...

Awk script to get time averages

I have a file with timestamps in the format: HH:MM:SS.MS e.g. 00:04:02.08 00:04:01.08 Each timestamp is on a different line, usually just two lines in a file I need to write an awk script to calculate average of these times. I am quite naive in awk scripting, so if someone can please give me a code-snippet, it will a lot of...

remove old backup files

# find /home/shantanu -name 'my_stops*' | xargs ls -lt | head -2 The command mentioned above will list the latest 2 files having my_stops in it's name. I want to keep these 2 files. But I want to delete all other files starting with "my_stops" from the current directory. ...

Threaded wget - minimalizing resources

Hi all - I have a script that is getting the GeoIP locations of various ips, this is run daily and I'm going to expect to have around ~50,000 ips to look up. I have a GeoIP system set up - I just would like to eliminate having to run wget 50,000 times per report. What I was thinking is, there must be some way to have wget open a con...

Bash / PHP quoting command line argument

I have a PHP program that uses a Bash script to convert a pdf. However if the filename contains spaces it is not passed through the bash script correctly. How do you escape filenames with spaces within a bash script? Do you have to do something special to quote the filename for the "OUTFILE" variable? Bash script: #!/bin/bash INFI...

Shell/Bash Command to get nth line of STDOUT

Is there any bash command that will let you get the nth line of STDOUT? That is to say, something that would take this $ ls -l -rw-r--r--@ 1 root wheel my.txt -rw-r--r--@ 1 root wheel files.txt -rw-r--r--@ 1 root wheel here.txt and do something like $ ls -l | magic-command 2 -rw-r--r--@ 1 root wheel files.txt I realize this wo...

replace words using grep and sed in shell

I have some 150 files and in them I want to remove this following code: <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="/height.js"></SCRIPT> What I'm doing is: sed -e 's/<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="/height.js"></SCRIPT>/ /' file_names This doesn't seem to work. I want to remove this script...

Commenting out a set of lines in a shell script

I was wondering if there is a way to comment out a set of lines in a shell script. How could I do that? We can use /* */ in other programming languages. This is most useful when I am converting/using/modifying another script and I want to keep the original lines instead of deleting. It seems a cumbersome job to find and prefix # for al...

shell script "for" loop syntax

I have gotten the following to work: for i in {2..10} do echo "output: $i" done It produces a bunch of lines of output: 2, output: 3, so on. However, trying to run the following: max=10 for i in {2..$max} do echo "$i" done produces the following: output: {2..10} How can I get the compiler to realize it should treat $ma...

Converting shell script to Objective-C CLI

I am planning to convert a rather long shell script I have into an Objective C command line tool. I'm planning to use NSTask to run the shell commands (this is a large script, and it has several thousand copy/move/delete operations). My question is, will continually allocating and deallocating NSTask objects to run all these commands res...

Forking / Multi-Threaded Processes | Bash

Hi all - I would like to make a section of my code more efficient. I'm thinking of making it fork off into multiple processes and have them execute 50/100 times at once, instead of just once. For example (pseudo): for line in file; do foo; foo2; foo3; done I would like this for loop to run multiple times. I know this can be done w...

Manually iterating a line of a file | bash

I realize I could do this in any other language - but with Bash - I've looked far and wide and could not find the answer. I need to manually increase $line in a script: Example: for line in `cat file` do foo() foo_loop(condition) { do_something_to_line($line) } done If you notice, every time the foo_loop iterates, $line stay...

python shell command - why won't it work?

Hi, I wonder if anyone has any insights into this. I have a bash script that should put my ssh key onto a remote machine. Adopted from here, the script reads, #!/usr/bin/sh REMOTEHOST=user@remote KEY="$HOME/.ssh/id_rsa.pub" KEYCODE=`cat $KEY` ssh -q $REMOTEHOST "mkdir ~/.ssh 2>/dev/null; chmod 700 ~/.ssh; echo "$KEYCODE" >> ~/.ssh/autho...

How can I make the list of letters from A to Z and iterate through them in the shell?

Say I want to iterate from letter A to letter Z in csh shell. How do I succinctly do that? In bash I would do something like for i in 'A B C ...Z'; do echo $i; done The point is I don't want to write A through Z, I want something like [A-Z] Can you suggest a one line suggestion in AWK or Perl? ...

How to synchronize local directory with remote ftp directory?

Our website relies on images from one of our manufacturers. The image directories are massive and getting them via FTP is an all day job. Now that we've downloaded the entire directory, we'd like to be able to periodically download files and directories that are new, or have been changed since the last time we downloaded them. We're t...

python system calls

Hi, with this command, I get only the file called OUTPUT (in reality I have many more --include flags) - so works as expected: os.system("rsync --rsh=ssh -arvuP --include='OUTPUT' --exclude='*' user@host:there/ ./here") In this case, the --include and --exclude flags are ignored: subprocess.call("rsync --rsh=ssh -arvuP --include='OUT...

count number of files generated from split command

I want to work on the files generated by the split command. How do I count these files? I am moving these to a separate directory, so it would help if someone could tell me how to store the output of ls -1|wc -l to a variable in a shell script. ...

Synchronize shell script execution

A modified version of a shell script converts an audio file from FLAC to MP3 format. The computer has a quad-core CPU. The script is run using: ./flac2mp3.sh $(find flac -type f) This converts the FLAC files in the flac directory (no spaces in file names) to MP3 files in the mp3 directory (at the same level as flac). If the destinatio...

Retrieving the First Non-Option Command Line Argument

I am trying to write a wrapper shell script that caches information every time a command is called. It only needs to store the first non-option argument. For example, in $ mycommand -o option1 -f another --spec more arg1 arg2 I want to retrieve "arg1." How can this be done in bash? ...