bash

how to grep a variable in the shell program?

#!/bin/bash for ((var=0; var<20; var++)) do echo " Number is: $(grep 'Multiple_Frame = echo **$var**' 20mrf.txt | wc -l)" >>statisic.txt done This shell program cannot produce correct result which maybe the reason of wrong variable returning in the second grep command. How can I grep a variable within the second echo sentence? to...

How to set my java programs locale to ccjk?

I'm reading an XML file inside a product to collects its inventory information i.e. various components it contains and when they are installed. I know from the product properties file that locale of the product is "ccjk". It stands for simplified Chinese for Japanese and Korean I guess. I want to set the locale of the shell before I run ...

execute conky with a cron job and bash

Hi, for my script in bash, I'd like to start conky if it's not running and pick a random wallpaper #! /bin/bash ## dependances : randomize-lines # otherwise wont work with cron export DISPLAY=0 while read line ; do echo $line | grep -vqe "^#" if [ $? -eq 0 ]; then export $line; fi done < ~/.dbus/session-bus/$(cat /var/lib/dbus/machine...

Test a file date with bash

Dear all, I am trying to test how old ago a file was created (in secondes) with bash in a "if" statement. I need creation date, not modification. Do you have any idea how to do this, without using a command like "find" with grep ? ...

Bash Scripting " [!: not found " errors, and how to write an or statement [Solved]

[Solved] See post by Dave Kirby. EDIT: Here is my updated code: #!/bin/sh files=`ls` if [ $# -ne 1 -o -f $1 ] then echo "Usage: $0 <directory>" exit 1 fi if [ ! -e $1 ] then echo "$1 not found" exit 1 elif [ -d $1 ] then cd $1 for f in $files do if [ ! -d "$f" ] then if [ ! -...

How do I include parameters in a bash alias?

Trying to create: alias mcd="mkdir $1; cd $1" Getting: $ mcd foo usage: mkdir [-pv] [-m mode] directory ... -bash: foo: command not found What am I doing wrong? ...

Check if Mac process is running using Bash by process name

How do you check if a process on Mac OS X is running using the process's name in a Bash script? I am trying to write a Bash script that will restart a process if it has stopped but do nothing if it is still running. ...

PID of last started process in Bash-Script

i am using the program synergy together with an ssh tunnel it works, i just have to open an console an type these two commands: ssh -f -N -L localhost:12345:otherHost:12345 otherUser@OtherHost synergyc localhost because im lazy i made an Bash-Script which is run with one mouseclick on an icon: #!/bin/bash ssh -f -N -L localhost:123...

Sending mail from bash shell script.

I am writing a bash shell script for Mac that sends email notification by opening an automator application that sends email out with the default mail account in Mail.app. The automator application also attaches a text file that the script has written to. The problems with this solution are It is visible in the GUI when sending It steal...

identify error in if statement

Here is the complete code.. What I'm trying to do is this - > I'm trying to find the average of the values in the second column of the files . If the file has 2.54 in its name, I want to find averages from files called file_2.54_even.xls and file_2.54_odd.xls . If the fiename does not have 2.54 in its name, then simply find the avera...

Error with redirection

I'm trying to find average of values in 2nd column in some files. Filenames have following pattern eg: tau_2.54_even_v1.xls tau_2.54_odd_v1.xls tau_1.60_v1.xls tau_800_v1.xls The other filenames can be obtained by replacing variable file with oter variables pmb , xhpl etc .. Here is the script I've written .. Can anyone kindly find ...

Bash: How do I truncate an array?

Hello. I'd like to change the value of an array and would appreciate any help. I got an array like this: users=(root isometric akau) (This is actually a list of current users) that I'd like to be able to test if the user exists and if they do not, then to remove the person from the array. I've tried experiment with this by putting ...

How to implement a web client in bash

Are you able to write a Bash script that will download an HTTP resource from the web? The inputs are: $hostname $port $path $output You can't: use external commands other than telnet (no sed, no awk, no wget, ...) use other shells You can: use /dev/tcp pseudo devices use telnet Your MUST pass this test (you can cha...

How to print variable inside awk

I want the awk to interpret the variable as follows #!/bin/bash file=tau f=2.54 order=even awk '{sum+=$2}; END {print '${file}_${f}_${order}_v1.xls', sum/NR}' ${file}_${f}_${order}_v1.xls >> safe/P-state-summary.xls I want the desired output as follows - tau_2.54_even_v1.xls sum/NR Can anybody help me out with this ? ...

Find lines containing all keywords in bash script

Essentially, I would like something that behaves similarly to: cat file | grep -i keyword1 | grep -i keyword2 | grep -i keyword3 How can I do this with a bash script that takes a variable-length list of keyword arguments? The script should do a case-insensitive match of lines containing all keywords. ...

Awk strftime on Mac OS X

The following command on my Mac (10.6) gives me an undefined function error: $ awk 'BEGIN{now=strftime("%D", systime()); print now}' awk: calling undefined function strftime source line number 1 On a Red Hat system, I get the expected result: $ awk 'BEGIN{now=strftime("%D", systime()); print now}' 12/01/09 What's the deal here? ...

Simple way to colour alternate output lines in bash

I have need to grep an entire directory for a string, and I get about 50 results. I would like to colour each second line, either text colour or background colour. Best would be a script that I can pipe the output of any command to, and so that it spits out the same (albeit coloured) output. ...

Bash script to connect to open port, send request, read response

Hi, I have a service running on localhost:port. In a bash script I want to connect to this port, send a request, and read back the response - essentially automating a telnet session. What's the best way of doing this? Am looking at /dev/tcp, netcat or telnet/expect. Thanks ...

Bash alias of an svn command piped to awk

I type in this command frequently, and was trying to alias it, and couldn't for some reason. for FILE in `svn stat | awk '{print $2}'`; do svn revert $FILE; done This obviously does a large number of svn reverts. when I alias it: alias revert_all="for FILE in `svn stat | awk '{print $2}'`; do svn revert $FILE; done" svn stat runs ...

How to determine function name from inside a function

Hello, If I have such a BASH script: #/bin/bash f() { # echo function name, "f" in this case } Is there any way to do this? This could be used in help messages such as printf "Usage: %s: blah blah blah \n" $(basename $0) >&2; Only in this case what I wanted is not $0, which is the file name of the script. Thanks! ...