bash

Use "history" command to fire last run command?

How do I use the "history" command to fire the last run command? ...

Running a script automatically when logging in via ssh

Hi there, I would like to know if there is a (simple) solution to the following issue: When I log in with ssh to a specific host, I would like to automatically execute a (bash)script on that host. This way I could -for example- load my aliases on that host. Definitively the bashrc script is not executed; The ssh configuration files d...

Reverse the contents of each line in a file?

I was hoping someone could help me, I need to reverse the contents of each line in a file. So basically this: 101.228.168.192 to 192.168.228.101 Is there a command I could use in a bash script, or even just the logic needed to get the job done. Thanks ...

bash cat multiple files content in to single string without newlines

i got some files with name start as eg_. and only each contains one single line eg_01.txt: @china:129.00 eg_02.txt @uk:219.98 eg_03.txt @USA:341.90 ...... i am expecting to cat them in to a single line to send by URL like: @china:129.00@uk:219.98@USA:341.90 i use echo cat eg_* it give me the output look like a string, but it actu...

bash command: search for class in file system of jars

I'm wanting to recursively search my maven repository (an n folder deep heirachy of jars) for a specific class inside an unknown jar. jar -tvf myJar.jar | grep ClassIWant.class works great for a known jar but I'm having problems piping/chaining bash commands to achieve a recursive search. Any hints much appreciated. Related: http://st...

Can I use netcat to run PHP CLI w/ arguments?

Hey all, I'm trying to create a debug listener that listens on a port for a data string and forwards it to a php script as an argument. How can I specify that the input to the port should be used as an argument? For example: The remote device send a string with comma separated values value1,value2,value3 and I'd like to run the command...

Trying to pass regular expression to grep

I'm trying to exctract error lines from my log file: I used this : more report.txt | grep -E (?i)(error) I'm getting this error msg : bash: syntax error near unexpected token `(' What am I doing wrong? I'm trying to extract all lines containing "Error" ignoring the case sensitivity so it can be error, Error, ERROR etc. ...

Unable to check cups printer status in Debian Squeeze

Sorry for my english! I'm using Debian squeeze and for an assignement, i have create 2 virtual pdf cups printers. Both are working very well. To test the different administion command; i try to disable one of the printer and move his queue file to the second one. I'm able to do it easily. Now, i wish to write a bash script that wil tes...

Looking the best way to start jboss

I'm trying find out, how to start jboss with cron job at a particular time. What I'm doing at the moment is setup a cron, then inside jboss startinstance script I put sleep 700 seconds untill jboss starts. Is there a better way to actually know when jboss has successfully started and then continue with the flow after, instead of sleep...

grep in IF statement

The following script portion read each line in $next. But when I try to grep particular pattern i.e. "MO" in $next, the error is shown on standard output as grep: 40922|OPR: No such file or directory grep: MO: No such file or directory grep: 12345|OPR: No such file or directory grep: MO: No such file or directory grep: 12345|12345|20...

Shell Scripting. Logical ERROR

I have written a shell script with a switch case and takes in options 1-5 and performs operations on the variables accordingly. My code works fine though theres a small change I would like to make in my code. When the code Enters the default case argument,after that it still prompts for "Enter two numbers: " and then prints "Invalid Op...

Can I Force MATLAB to quit after user presses Control-C?

I'm running MATLAB (command line version) from a shell script, and I'd like it to preserve shell behavior where if you press Ctrl-C it exits. But instead it wants to keep control of the terminal and I (or my poor users after me) have to type quit(1) to make it quit and tell the shell it failed. You can't intercept Ctrl-C with a try/cat...

Sorting csv columns in bash, reading bash output into python variables..

Hi I have a ton of data in multiple csv files and filter out a data set using grep: user@machine:~/$ cat data.csv | grep -a "63[789]\...;" 637.05;1450.2 637.32;1448.7 637.60;1447.7 637.87;1451.5 638.14;1454.2 638.41;1448.6 638.69;1445.8 638.96;1440.0 639.23;1431.9 639.50;1428.8 639.77;1427.3 I want to figure out the data set which has...

Bash redirection help

Hi Guys, I'm having a little issue getting quite a simple bash script running. The part that's working: qstat -f $queuenum | grep -Po '(?<=PBS_O_WORKDIR=).*(?=,)' Outputs a directory to the screen (for example): /short/h72/SiO2/defected/2-999/3-forces/FORCES_364 All I want to do is change directory to this folder. Appending...

AWK/BASH: how to match a field in one file from a field in another?

Hi all, I have 2 files, the first contains the following: ... John Allen Smith II 16 555-555-5555 10/24/2010 John Allen Smith II 3 555-555-5555 10/24/2010 John Allen Smith II 17 555-555-5555 10/24/2010 John Doe 16 555-555-5555 10/24/2010 Jane Smith 16 555-555-5555 9/16/2010 Jane Smith 00 555-555-5555 10/24/2010 ... and the second fil...

Remove First Page from a Series of PDFs

Hi, I have a series of PDFs (Computer Gaming World issues) and I want to remove the first page from the pdf file of each issue. There are 100 issues, so a GUI is just not gonna cut it. I used pdftk to remove the first page from one issue: pdftk 1981_1112_issue1.pdf cat 1 output 1.pdf My problem is that I do not want to have to modify ...

Shell program doesn't work

i have my shell code: #!/bin/sh if [ ! -d $1 ] then echo $1 nu este director exit1 fi ls -R $1 >temp permission= ls -al $1 | cut -d" " -f1 for i in `cat temp` do perm= ls -l $i | cut -d" " -f1 if [ $permission -ne $perm ] then n=`expr $n + 1` fi echo $n done and my statement which sounds like this:for an folder given...

how to use ctrl-D in a shell script

Hi Everyone, I have a bash shell script that requires ctrl-D to break out of the terminal.can anyone tell me how to use it in the shell script example ssh host last --->displays the list of users who were logged on to that host i have different hosts the output is appended to one final and when i'm executing this particular shell s...

AWK/SED remove columns that contain parenthesis

Hi all, I was wondering if it would be possible to remove columns within a data file that contain any parenthesis that can be contained in ANY column. For example ... John Doe (Tech Department) 09/12/2009 555-555-5555 Jane Smith 09/12/2009 555-555-5555 (Suspended) Alfred doe 555-555-5555 (Vacation) 09/09/2011 ... So then I would like...

-bash is messed up?

Trying to figure out why I could not set up Heroku Gem and following this answer SO 2396004 (Heroku Gem Doesn't Work). I think I might have messed up my system. Now I am typing heroku list and I get (-bash: heroku: command not found) and when I type in ruby -v I get (-bash: ruby: command not found) BELOW IS THE MOST RECENT OUTPUT za...