bash

How do I append all files in current and subdirs as command arguments?

I have a directory like this: dir dir/somefile.txt dir/subdir/subsub/somefile2.txt dir/subdir2/somefile.txt and I want to open all the files in all the subdirectories in a single instance of a command. I was trying find with -exec, or xargs, but these open each file with a separate instance of a command. Basically, I want something t...

awk and bash script.

I have a tgz file which contains a version file, version.txt. This file has only one line "version=1.0.0". This tgz file is present in two different directories and has the same name. My requirement is that I need to use bash script and awk to determine which of these two tgz files is of the latest version. i.e. tgz file having 1.0.0 is...

How to grab live text from a URL?

Im trying to grab all data(text) coming from a URL which is constantly sending text, I tried using PHP but that would mean having the script running the whole time which it isn’t really made for (I think). So I ended up using a BASH script. At the moment I use wget (I couldn’t get CURL to output the text to a file) wget --tries=0 --ret...

pipelines vs for

Starting to play with bash on Linux, I am trying to perform a clearcase operation on all files resulting from an other clearcase operation. In other words I want to check in all the checked out files. The command to list checked out files is: cleartool lsco -short -rec. The command to check in a file is: cleartool ci -nc filename. I am...

Monitoring bash script won't terminate

Hi all, I have this bash script whose job is to monitor a log file for the occurrence of a certain line. When located, the script will send out an email warning and then terminate itself. For some reason, it keeps on running. How can I be sure to terminate bash script below: #!/bin/sh tail -n 0 -f output.err | grep --line-buffered "Exc...

Check if Screensaver is Active using Mac Bash Script Command

I've found many useful Bash commands that can execute OS X behaviors from the command line such as: screencapture -x -C $FILENAME Is there such a command that can check if the screen saver is active? ...

Hashing Multiple Files

Problem Specification: Given a directory, I want to iterate through the directory and its non-hidden sub-directories,  and add a whirlpool hash into the non-hidden file's names. If the script is re-run it would would replace an old hash with a new one. <filename>.<extension>   ==>  <filename>.<a-whirlpool-hash>.<e...

looping 1, 2 and 3 numbers

supposed to be I have 3 filenames file-00 file-01 file-02 I'm trying to replicate those files to file-03, file-04, file-05...file-98, file-99, file-100 based on the original files. So in bash I do #!/bin/bash x=0 y=1 z=2 for i in $(seq 0 100); do cp file-00 file-$((x=x+2)); cp file-01 file-$((y=y+3)); cp file-02 file=...

How to write bash script to search for IP's in a file and put write them to another file?

I need to write a bash script that will take a grepable nmap output file that displays IP addresses with port 80 open and copy the IPs that have port 80 open to another text file. The output looks similar to this: # Nmap 4.76 scan initiated Thu Dec 3 13:36:29 2009 as: nmap -iL ip.txt -p 80 -r -R -PN --open -oA output Host: 192.168.1....

Parse Date in Bash

I need to parse a date (format: YYYY-MM-DD hh:mm:ss) in bash. I'd like to end up with all fields (years, months, days, hours, minutes, seconds) in different variables. ...

Using xvkbd to read a barcode. How to disable Enter key?

Hello, I am using zbarcam to read barcode from a webcam in my webapps. But, since zbarcam display a \n at the end, my form is submit. Here is what I use : read_one.py #!/usr/bin/python from sys import argv import zbar import webbrowser # create a Processor proc = zbar.Processor() # configure the Processor proc.parse_config('enable'...

How can I use bash to parse out only a section of a variable with different delimiters?

I have a loop in a bash file to show me all of the files in a directory, each as its own variable. I need to take that variable (filename) and parse out only a section of it. Example: 92378478234978ehbWHATIWANT#98712398712398723 Now, assuming "ehb" and the pound symbol never change, how can I just capture WHATIWANT into its own varia...

how can this src vs. build tree timestamp comparison be faster? (bash)

for n in `cd src; find . -name "*.java"; cd -`; do a=`echo $n | cut -d '.' -f2`; if [[ src/$a.java -nt build/$a.class ]]; then echo src/$a.java; fi; done It lists all the java files in the src tree; then for each one, it removes the suffix ".java" (cut -d '.' -f2 because find . output is prefixed with .). It then uses -nt to ...

Python bash pipe

I want to pipe a python script's output to a bash script. What i did so far was i tried to use os.popen(), sys.subprocess(), and tried to give a pipe for an example os.popen('echo "P 1 1 591336 4927369 1 321 " | v.in.ascii -zn out=abcx format=standard --overwrite') but this didn't work, the values "591336" and "4927369" are the variab...

Remove slash from the end of a variable

hi folks, the bash auto completion make a / at the end of a directory how i can strip this out? Thanks for hints. #!/bin/sh target=$1 function backup(){ date=`date "+%y%m%d_%H%M%S"` PWD=`pwd` path=$PWD/$target tar czf /tmp/$date$target.tar.gz $path } backup ...

deleting brackets in a file using sed

Can anyone help me in deleting brackets in a file ? here is my script .. #!/bin/bash for file in fftw is_c mpi_tile pmb tau xhpl do for state in C0 C1 C2 C4 do printf "${file}_${state}_v1.xls" sed -e 's/\(//' ${file}_${state}_v1.xls sed -e 's/\)//' ${file}_${state}_v1.xls awk '{sum+=$3} ; END {print " ", su...

Simple math statements in bash in a for loop.

Hi. I'm quite new to bash scripting and usually avoid it all costs but I need to write a bash script to execute some simple things on a remote cluster. I'm having problems with a for loop that does the following: for i in {1..20} do for j in {1..20} do echo (i*i + j*j ) **.5 <--- Pseudo code! done done Can you hel...

Bash Daemon Named "sh" or "sleep" not the filename....

I have created a simple bash script, chmod +x, and successfully am running it as a background service. But, the script is called "sh" or "sleep" or whatever command seems to be running at the time, not my script name, when I view a process list. How do I name the process of my bash script so I can distinguish it? I want to be sure th...

Detecting program errors in bash scripts?

I'm trying to write my first semi advanced bash script that will take input in the form of a filename referring to an avi video, send it to ffmpeg to convert to a mp4 (preserving the original name) and then hand it off to MP4Box. The below is pretty much what I'm doing... #!/usr/bin/bash ffmpeg -i $0 -acodec libfaac -ab 128k -ac 2 -vco...

Grep search strings with line breaks

How to use grep to output occurrences of the string 'export to excel' in the input files given below? Specifically, how to handle the line breaks that happen in between the search strings? Is there a switch in grep that can do this or some other command probably? Input files: File a.txt: blah blah ... export to excel ... blah b...