bash

Find does not work in Expect Send command

I run this bash command to display contents of somefile.cf in a Weblogic domain directory. find $(/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed -e 's/weblogic.policy//' -e 's/security\///' -e 's/dep\///' | awk -F'/' '{print "/"$2"/"$3"/"$4"/somefile.cf"}' | sort | un...

How can I make this if's work in Bash ?

In bash how can I make a construction like this to work: if (cp /folder/path /to/path) && (cp /anotherfolder/path /to/anotherpath) then echo "Succeeded" else echo "Failed" fi The if should test for the $? return code of each command and tie them with &&. How can I make this in Bash ? ...

linux piping ( convert -> pdf2ps -> lp)

Ok, so I can print a pdf doing: pdf2ps file.pdf - | lp -s But now I want to use convert to merge several pdf files, I can do this with: convert file1.pdf file2.pdf merged.pdf which merges file1.pdf and file2.pdf into merged.pdf, target can be replaced with '-'. Question How could I pipe convert into pdf2ps and then into lp though...

bash, Linux: Set difference between two text files

Hi, I have two files A-nodes_to_delete and B-nodes_to_keep. Each file has a many lines with numeric ids. I want to have the list of numeric ids that are in nodes_to_delete but NOT in nodes_to_keep, e.g. . Doing it within a PostgreSQL database is unreasonably slow. Any neat way to do it in bash using Linux CLI tools? UPDATE: This woul...

Script telnet on webserver

Hi I would like to script telnet to test my website inputs handling. I can do it manually : telnet localhost 8888 ... GET / HTTP/1.1\n Host: localhost ...html response But I can pass command to telnet in my shell script ! I've tried : (echo "GET / HTTP/1.1\n"; echo "Host: localhost \n\n"; sleep 1) | telnet localhost 8888 It pr...

How to use file contents as command-line arguments?

I'd like to use arguments from file as command-line arguments for some commands like gcc or ls. For example gcc -o output -Wall -Werro as file consist of: -o output -Wall -Werro Used for gcc command-line call. ...

How to change the value of value in BASH ??

Hello All, Let's say i have the Following, Vegetable=Potato ( Kind of vegetable that i have ) Potato=3 ( quantity available ) If i wanna know how many vegetables i have (from a script where i have access only to variable Vegetable), i do the following: Quantity=${!Vegetable} But let's say i take ...

get bash history to vi

When I try to read bash history into vim, I get nothing. :r !history If I just execute the command, i.e. :!history instead of history I get a snapshot of my terminal as it looked before I started vim. How can I read the output of "history" into vim? Reading the contents of .bash_history won't do as I save history with timestamps: ...

What's the equivalent of the bash in windows batch?

while [1 = 1] do eject sleep 1 eject -t sleep 1 done And this is said to be the same: watch -n 1 eject -T What does it do?What's the equivalent in batch? ...

BASH statements execute alone but return "no such file" in for loop.

Another one I can't find an answer for, and it feels like I've gone mad. I have a BASH script using a for loop to run a complex command (many protein sequence alignments) on a lot of files (~5000). The loop produces statements that will execute when given alone (i.e. copy-pasted from the error message to the command prompt), but which r...

Add at the end of the line with sed

Hi, given a plain text document with several lines like: c48 7.587 7.39 c49 7.508 7.345983 c50 5.8 7.543 c51 8.37454546 7.34 I need to add some info 2 spaces after the end of the line, so for each line I would get: c48 7.587 7.39 def c49 7.508 7.345983 def c50 5.8 7.543 def c51 8.37454546 7.34 def I need to do this for thousan...

BASH Arithmetic Expressions

I had used several ways to do some simple integer arithmetic in BASH (3.2). But I can't figure out the best (preferred) way to do it. result=`expr 1 + 2` result=$(( 1 + 2 )) let "result = 1 + 2" What are the fundamental differences between those expressions? Is there other ways to do the same? Is the use of a tool like bc mandatory f...

Modify an exact line number of a text file and add certain string after the end of the line

Hi, given a plain text file, how can I do, using bash, awk, sed, etc, to, at the line number NLINE, add the string STR, just n spaces after the end of the line? So, for instance, if this is the line NLINE: date march 13th for 5 spaces, we get date march 13th STR and one gets the modification in a new file. Thanks ...

How do I reload .bashrc without logging out and back in?

Hello StackOverflowers, If I make changes to .bashrc, how do I reload it without logging out and back in? I'm embarrassed that I don't know the answer to this question, since I do a fair amount of bash scripting. I'm also couldn't decide if I should post this on ServerFault, but since I do more scripting than sysadmin, I chose StackOve...

How to exit a bash loop using ls?

I want to loop over a series of files in a directory in batches and then exit when the directory is empty. At $work 'myprog' is actually a program which processes (and archives) incoming email in a Maildir in batches of 100. I am after something simple I can put into cron. #!/bin/bash # Setup mkdir -p foo && touch foo/file_{1,2,3,4}....

Cygwin bash syntax error - but script run perfectly well in Ubuntu

#!/bin/bash if test "$#" == "4"; then echo "$*"; else echo "args-error" >&2; fi; This little code snippet troubles me a lot when I tried to run it on both Ubuntu and Cygwin. Ubuntu runs bash version 4.0+ whereas Cygwin runs 3.2.49; But I reckon version collision shall not be the cause of this, this code runs well under fedora 10 which...

How do I conditionally redirect the output of a command to /dev/null?

I have a script. I would like to give this script a quiet mode and a verbose mode. This is the equivalent of: if $verbose then redirect="> /dev/null" fi echo "Verbose mode enabled" $redirect # This doesn't work because the redirect isn't evaluated. I'd really like a better way of doing this than writing if-elses for every statemen...

Sending STDERR to logger

Im writing a bash-script to perform an offsite backup, using rsync over SSH. I'm able to send STDOUT to logger, for logs via rsync --del -az -e 'ssh -i mycrt.crt' /home/gnutt/backup/ me@offisite:backup | logger -i But I want to send STDERR instead, so if there is a problem, such as that offsite is unavailable, that output should be se...

Inline comments for bash?

I'd like to be able to comment out a single flag in a one-line command. Bash only seems to have `from # till end-of-line' comments. I'm looking at tricks like: ls -l $([ ] && -F is turned off) -a /etc It's ugly, but better than nothing. Anybody has any better suggestions? UPDATE The following seems to work, but I'm not sure whether ...

How to send a signal SIGINT from script to script ? BASH

I want to trap a signal send from Script-A.sh to Script-B.sh so in Script-A.sh i use the command (Send SIGINT to Script-B.sh) kill -2 $PID_Script-B.sh And in Script-B.sh i catch the signal and call function Clean trap 'Clean' 2 It does not work, instead the Script-B.sh is killed right away without per...