bash

The number of processes a user is running using bash

Hi, I would like to know how I could get the number of processes for each user that is currently logged in. Thank you. ...

How to write a daemon

Does anyone know how to write a daemon? I want to write a daemon which executes a script to move a file from one particular directory to another. ...

Print STDOUT in the middle of 2 Pipes in Solaris(bash)

http://www.webdesignerdepot.com/rss.htm I have the same issue. This command: ./somescript.sh > ../log/scriptlog.log requires the output of a command go to std out. but inside the script command | mailx -s "Subject" [email protected] what I would like to do is something like : command | tee > /dev/stdout | mailx -s "Subjec...

Parse folder name in bash

I have folders with the naming convention: yearmonthday_jobcode_descriptor ie 20101007_GR1234_Whatsit I'm attempting to write a script that does a few things: move any folders where the date is older than $X into ./old move any folders where the date is in the future ./old move any folders that dont conform to the convention ./old d...

backing up subversion repositories

Hello, CentOS 5.3 subversion 1.4.2 I forgot to add. Currently the total repository size is about 5GB, but that will grow over time. We have our source code and documents on our internal server running CentOS 5.3 and we are using subversion 1.4.2. We are looking for a backup strategy. We want to perform daily backups. We have about 30...

How to run 'cd' in shell script and stay there after script finishes?

I used 'change directory' in my shell script (bash) #!/bin/bash alias mycd='cd some_place' mycd pwd pwd prints some_place correctly, but after the script finished my current working directory doesn't change. Is it possible to change my path by script? ...

String tokenisation algorithm won't tokenise

Morning all, I am writing a bash script to extract the values of certain XML tags from all files in a given directory. I have decided to do this by tokenising each line and returning th4e relavent token. The problem is that it isn't tokenising correctly and I can't quite work out why. Here is the smallest example that I could make tha...

Find which drive corresponds to which USB mass storage device in Linux

I have several USB mass storage flash drives connected to a Ubuntu Linux computer (Ubuntu 10.04.1, kernel 2.6.32-25-386), and I need to tell them apart programatically (from bash if possible, but I'm not afraid of compiling either) - I need to find which block device corresponds to which physical device (e.g. /dev/sdb1 -> device in USB p...

Kill all processes launched inside an xterm when exit

I'm using Cygwin to start some servers. Each server is launched inside an xterm with a bunch of command like this one: xterm -e $my_cmd /C & Is there an easy way to kill all launched children (xterm and their running commands) in a row ? I want also to be able kill a particular launched command when I close its parent xterm. Someo...

How does bash parameter expansion work?

I'm trying to understand a bash script with help of google :) Then I stumbled upon this: DIR=${1:-"/tmp"} What does that mean? Google does not give any relevant result :( ...

svn update of directory with muliply repositories checkouts

Hi, I have a development directory that contains checkouts from svn repositories that stays in non svn directories. I would like to update all of dirs being in the svns. Dir structure is similar to one below: How would you solve the issue? I am came with "brute force" solution, but it is not very much intelligent: for i in `fi...

Keeping a bash script running along the program it has started, and sending the program input

I'm writing a very simple script to control a process, script checks if the process is running, if not: executes it. I need to expand this with the ability to kill a specific process instance (very one one script has started) after a specified amount of time. Problem is, once bash script is executed it isn't running until the executed p...

I'm having trouble performing arithmetic expressions in UNIX.

I have the following script: #!/bin/sh r=3 r=$((r+5)) echo r However, I get this error: Syntax error at line 3: $ unexpected. I don't understand what I'm doing wrong. I'm following this online guide to the letter http://www.unixtutorial.org/2008/06/arithmetic-operations-in-unix-scripts/ ...

Bash - Hex to String

In bash, how can I convert an hex-encoded string like this: 2e2f65202d6b2022616622 or \x2e\x2f\x65\x20\x2d\x6b\x20\x22\x61\x66\x22 (or something similiar) to: ./e -k "af" ... and then execute it? Thanks! ...

Bash Nested Loops, mixture of dates and numbers

Hi, I am trying to output a range of commands with different dates and numbers associated. for each hour eg. Output im trying to do in a loop is: shell.sh filename<number e.g. between 1-24> <date e.g. 20100928> <number e.g. between 1-24> <id> So basically the the above will generate an output done 24 times for each particular day w...

how to automatically run a bash script when my qsub jobs are finished on a server?

I would like to run a script when all of the jobs that I have sent to a server are done. for example, I send ssh server "for i in config*; do qsub ./run 1 $i; done" And I get back a list of the jobs that were started. I would like to automatically start another script on the server to process the output from these jobs once all are c...

Easiest way to get count val from mysql in bash

Maybe i should use python or perl but i dont know any. I have 4 statements and i would like to check if there are any errors longer then an hour. My user is setup so i dont need to enter a mysql user/pass. This statement is in mysql_webapp_error_check.sh #!/bin/bash mysql testdb -e "select count(*) from tbl where last_error_date < DATE...

How can you redirect a script's output through a process?

I want to redirect a bash script's output through a logging program. Specifically, Apache's logrotate utility. The redirection needs to be set within the script itself. If the redirection were done on the command line, while executing the script, it would look like this: myscript | logrotate -l $LOGFILE.%F 86400 2>&1 Here is some pse...

using sed to replace the contents of a file is not working in bash script

I have the following sed -e 's/<em\:update.*//g' install.rdf > install.rdf in a bash script, and it works on command line, but in the bash script install.rdf ends up a blank file. When I run sed -e 's/<em\:update.*//g' install.rdf > install.rdf command line, then 2 lines are stripped out of the file. Any idea why sed -e 's/<em\:update....

Trouble nesting expressions in UNIX.

I have the following UNIX statement: #!/bin/bash $x=$((grep ^'[a-z]' $1 | wc -l)) echo "$x" However, I'm getting an error message relating to a missing operand whenever I try to run the script. Is there any way to assign a variable a value like so in UNIX? EDIT: Well, it became clear to me that grep cannot seem to examine single wor...