shell-scripting

Checking return value of a C++ executable through shell script

I am running a shell script on windows with cygwin in which I execute a program multiple times with different arguments each time. Sometimes, the program generates segmentation fault for some input arguments. I want to generate a text file in which the shell script can write for which of the inputs, the program failed. Basically I want t...

Assign a makefile variable value to a bash command result ?

Hello , I'm trying to assign the output of this command ( that is in my makefile ) to the makefile HEADER var like in this following line of code: HEADER = $(shell for file in `find . -name *.h`;do echo $file; done) The problem is that if I print HEADER in my makefile using: print: @echo $(HEADER) I get ile ile ile ile ile il...

Find all words containing characters in UNIX

Given a word W, I want to find all words containing the letters in W from /usr/dict/words. For example, "bat" should return "bat" and "tab" (but not "table"). Here is one solution which involves sorting the input word and matching: word=$1 sortedWord=`echo $word | grep -o . | sort | tr -d '\n'` while read line do sortedLine=`echo ...

what is more efficient: read in file from java or shell script?

I'm trying to figure out what is more efficient in terms of server load which is pretty big at the moment, additional overload wouldn't be a great idea. Here is what I need to do : I have a log file which changes, sometimes every second other times every few minutes or so which is not really relevant to this question. I'm trying to find...

shell-scripting: Use a pipe as an input for tar

Hi there! I'm trying to figure out a way to use tar+pipes on a Ubuntu Server LTS. I've got a postgresql command (pg_dump) that outputs lots of sql on the standard output: pg_dump -U myUser myDB I know how to redirect that to a file: pg_dump -U myUser myDB > myDB.sql In order to save some disk space, I would rather have it compres...

Select a random item from an array

I'm creating a bot in Shell Script: # Array with expressions expressions=("Ploink Poink" "I Need Oil" "Some Bytes are Missing!" "Poink Poink" "Piiiip Beeeep!!" "Hello" "Whoops! I'm out of memmory!") # Seed random generator RANDOM=$$$(date +%s) # Loop loop loop loop loop loop ... while [ 1 ] do # Get random expression... select...

Read a file's content (with spaces) into an array

I'm creating a Shell Script, and I have a file like this called expressions.txt: "Ploink Poink" "I Need Oil" "Some Bytes are Missing!" "Poink Poink" "Piiiip Beeeep!!" "Whoops! I'm out of memory!" "1 + 1 = 3" "Please fix my bugs!" "Goeiedag!" "Hallo!" "Guten Tag!" "Hyvää Päivää!" "Добрый день" "!สวัสดี" "Bonjour!" "!مرحبا" "!שלום" "Γειά!...

How do I use cp to copy one directory to new name repeatedly and correctly?

I am writing a makefile. However except for the path expansion and restrictions on what I can do, this is basically a shell scripting question. As part of the make process, I want to copy a directory to the destination. My source directory and destination directory are variables, so I can't assume a lot about them. They may be fully qual...

When running a shell script, how can you protect it from overwriting or truncating files?

If while an application is running one of the shared libraries it uses is written to or truncated, then the application will crash. Moving the file or removing it wholesale with 'rm' will not cause a crash, because the OS (Solaris in this case but I assume this is true on Linux and other *nix as well) is smart enough to not delete the in...

Is there a command similar to iwevent to monitor eth0 state?

I want to setup my computer to run certain commands when I join or leave certain networks (ie: Start up Synergy when at work; Start up ssh when on the lan at home so I can sync, etc...). I found iwevent which outputs events to the wireless interface that I can watch. However I can't find an equivalent to watch when eth0 is connected or ...

Get ceiling integer from number in linux (BASH)

How would I do something like: ceiling(N/500) N representing a number. But in a linux bash script ...

Round a divided number in Linux

How would I round the result from two divided numbers, e.g. 3/2 As when I do testOne=$((3/2)) $testOne contains "1" when it should have rounded up to "2" as the answer from 3/2=1.5 ...

script unable to find directories/files when running from qsub cluster script

I'm calling several unix commands and python on a python script from a qsub shell script, meant to run on a cluster. The trouble is that when the script executes, something seems to go awry in the shell, so that directories and files that exist are not found. For example, in the .out output files of qsub I see the following errors: cd...

UNIX Shell-scripting: UDV

I am writing a simple unix shell script: #!/bin/bash # abort the script if a command fails set -e # abort the script if an unitialized shell variable is used set -u i = 0; while [$i -l 1] do src/meshpro input/martini.off video/noise/image$i.off -noise $i src/meshvi...

Identifying and removing null characters in UNIX

I have a text file containing unwanted null characters. When I try to view it in I see ^@ symbols, interleaved in normal text. How can I: a) Identify which lines in the file contains null characters? I have tried grepping for \0 and \x0, but this did not work. b) Remove the null characters? Running strings on the file cleaned it up, bu...

Processing a log to fix a malformed IP address ?.?.?.x

I would like to replace the first character 'x' with the number '7' on every line of a log file using a shell script. Example of the log file: 216.129.119.x [01/Mar/2010:00:25:20 +0100] "GET /etc/.... 74.131.77.x [01/Mar/2010:00:25:37 +0100] "GET /etc/.... 222.168.17.x [01/Mar/2010:00:27:10 +0100] "GET /etc/.... My humble beginnings.....

Shell script is not accepting a directory (D drive) on a windows machine.

Shell script is not accepting a directory (D drive) on a windows machine. $ ./XXXZZ.sh /d/metrics/ABClogs/QWE_ASD_ZXC-030310.zip : No such file or directorymetrics/bin/stddefs.sh The file is there in that path, infact. Don't know why it is not able to see the 'D' drive. Can some please suggest me in this regard? ...

send output to file from within shell script

I'm creating a script for users to run. I need to redirect the output to a file I'm creating from inside the script (hostname-date). I have all the pieces except for how to copy the output of the script from inside the same script. All the examples I can find call the script and > it into the log, but this isn't an option. -Alex ...

How to write ONE line of command that scp all the sub-directories in a directory to a remote machine

something like: scp -r all_directories_in_current_directory fenix@xxxxx:~/data anyone can give me a clue? ...

Trouble with piping through sed

I am having trouble piping through sed. Once I have piped output to sed, I cannot pipe the output of sed elsewhere. wget -r -nv http://127.0.0.1:3000/test.html Outputs: 2010-03-12 04:41:48 URL:http://127.0.0.1:3000/test.html [99/99] -> "127.0.0.1:3000/test.html" [1] 2010-03-12 04:41:48 URL:http://127.0.0.1:3000/robots.txt [83/83] -> ...