bash

ssh-agent and crontab -- is there a good way to get these to meet?

I wrote a simple script which mails out svn activity logs nightly to our developers. Until now, I've run it on the same machine as the svn repository, so I didn't have to worry about authentication, I could just use svn's file:/// address style. Now I'm running the script on a home computer, accessing a remote repository, so I had to c...

How can I tell bash to properly escape expanded strings?

Suppose I have a directory containing the files foo bar.txt foo baz.txt (each with a space between 'o' and 'b'). Suppose I would like to do this: for f in *.txt; do mv ${f} `basename ${f} .txt`; done This fails because bash expands *.txt to foo bar.txt foo baz.txt instead of foo\ bar.txt foo\ baz.txt i.e. properly escaped ...

Using awk (or sed) to remove newlines based on first character of next line

Hello everyone, here's my situation: I had a big text file that I wanted to pull certain information from. I used sed to pull all the relevant information based on regexp's, but each "piece" of information I pulled is on a separate line, I'd like for each "record" to be on its own line so it can be easily imported into a DB. Here's a sam...

Start java process at boot and auto-restart on death

I have two requirements for my Java app. If it dies, restart it. If the server reboots, restart it - simple enough. Using the answer here I have a script that will restart when the java application dies. #!/bin/bash until java -Xms256m -Xmx768m -jar MyApp.jar; do echo "MyApp crashed with exit code $?. Respawning... " >" and it...

How to hierarchically (levelize) arrange list of file names with matching pre-fixes (LCS) defining the hierarchy - preferably using shell tools

Source code dirs have meaningful file names. for example AAAbbbCCddEE.h/.cxx : where AAA, bb CC could refer to abbrev of sub-systems or just a functionality-description like "...Print..." or "...Check..." as the code-base grows we land up with more than handful files per dir. it becomes daunting just to know what is doing what especial...

BASH: Test whether string is valid as an integer?

Hello All, I'm trying to do something common enough: Parse user input in a shell script. If the user provided a valid integer, the script does one thing, and if not valid, it does something else. Trouble is, I haven't found an easy (and reasonably elegant) way of doing this - I don't want to have to pick it apart char by char. I know t...

a script to log into webpage

I want to write a script to log in and interact with a web page, and a bit at a loss as to where to start. I can probably figure out the html parsing, but how do I handle the login part? I was planning on using bash, since that is what I know best, but am open to any other suggestions. I'm just looking for some reference materials or ...

how do I paste text to a line by line text filter like awk, without having stdin echo to the screen?

I have a text in an email on a windows box that looks something like this: 100 some random text 101 some more random text 102 lots of random text, all different 103 lots of random text, all the same I want to extract the numbers, i.e. the first word on each line. I've got a terminal running bash open on my Linux box... If these were ...

if then else statement to find files

Hello how can i use the if/else statement to look for files. Lets say if i have a file.txt in root, i want to be able to write a scrip that says if [ file.txt ] does not exist then use the find / -newer sshh > file.txt and or else use [file.txt] and then mail the changes if anything has changed. ...

Writing .Ts file 'on demand' (inotify ?...)

Hello, I have a mediaplayer that can only read samba shared files. I would like to play http stream (from my dreambox for instance). My idea is to share a folder on my linux. In this share, I will put a (fake?) file for each tv channel I want to be able to watch (ex : channel1.ts, channel2.ts ...). The mediaplayer can only read these ...

Match URL link from input string

How do I match the URL address in this string, I have other code that matches text and it seems to work, but when I try to use it here, it doesn't, it keeps saying there is "No such file or directory. I didn't know grep -o only worked on files? matchString='url={"urlPath":"http://www.google.com/","thisIsOtherText"' array=($(grep -o 'url...

What's the difference between -> result=$(ls -l) (or) -> result=`ls -l`

I'v run both commands and they both seem to do the same thing, is this true or is there something happening I'm not seeing? These two appear to do the same thing: result=$(ls -l) result=`ls -l` ...

How to exit all the calling scripts in bash?

Hi, Lets say I have the following scripts a.sh echo in a if test 1 -ne 2; then echo oops exit 1 fi b.sh echo in b ./a.sh echo in b 2 When running b.sh, I want it to exit if a.sh exited. How do I do this? (The current output is in b in a oops in b 2 And that's not what I want) Thanks, Rivka ...

Using grep with a complex string

Hi, I am looking in the content of several files for strings like: (2E)-3-({5,6-dihydroxy-3-methyl-2-oxo-4-[(1E)-prop-1-en-1-yl]-2,3-dihydro-1-benzofuran with grep, so I try to do: grep -n "(2E)-3-({5,6-dihydroxy-3-methyl-2-oxo-4-[(1E)-prop-1-en-1-yl]-2,3-dihydro-1-benzofuran" *.data but I get errors, probably due to the fact that ...

Symbolic errno to String

Is there a command-line tool that will take a symbolic errno such as EINVAL and print the corresponding string, Invalid argument? I would like to avoid having to find that EINVAL is value 22 on my system and then using$ perror 22. Ideally I could write something like $ errorcommand EINVAL Invalid argument $ ...

With sed or awk, how do I match from the end of the current line back to a specified character?

I have a list of file locations in a text file. For example: /var/lib/mlocate /var/lib/dpkg/info/mlocate.conffiles /var/lib/dpkg/info/mlocate.list /var/lib/dpkg/info/mlocate.md5sums /var/lib/dpkg/info/mlocate.postinst /var/lib/dpkg/info/mlocate.postrm /var/lib/dpkg/info/mlocate.prerm What I want to do is use sed or awk to read f...

bash: how _best_ to create a script from another script

What is a generalized way to create a bash script from another script. For instance: $./script1 arg1 arg2 > script2 $./script2 $arg1 arg2 I can think of a few ways like simply echoing the output but I was wondering if there was a better way or a command I didn't know about and a google search wasn't very helpful. Thanks in advance f...

Match domain name from url (www.google.com=google)

So I want to match just the domain from ether: http://www.google.com/test/ http://google.com/test/ http://google.net/test/ Output should be for all 3: google I got this code working for just .com echo "http://www.google.com/test/" | sed -n "s/.*www\.\(.*\)\.com.*$/\1/p" Output: 'google' Then I thought it would be as simple as doin...

How to make a bash script that creates 40 simultaneous instances of a program?

I am new to bash and Linux. I have a program I have written that I want to create multiple simultaneous instances of. Right now, I do this by opening up 10 new terminals, and then running the program 10 times (the command I run is php /home/calculatedata.php What is the simplest way to do this using a bash script? Also, I need to know ...

How to evaluate http response codes from bash/shell script?

I have the feeling that I'm missing the obvious, but have not succeeded with man [curl|wget] or google ("http" makes such a bad search term). I'm looking for a quick&dirty fix to one of our webservers that frequently fails, returning status code 500 with an error message. Once this happens, it needs to be restarted. As the root cause se...