shell-scripting

What among Bash/Python/Perl/Ruby/Sed/Awk for System administration , coding accessories.

I know the question is very subjective. But I cannot form the question in a much more better manner. I would appreciate some guidance. I often as a developer feel how easier it would have been for me if I could have some tools for doing some reasonably complex task on a log file , or a set of source files, or some data set etc. Clearly...

Executing oracle queries in Shell Script

Please tell me how can i excute an oralce query inside a shell script.I am writing a shell script where I need to execute the oracle queries and scripts inside the shell script. What is the purpose of these lines sql_file=sachin.sql cat <<!SQL > $sql_file select $1 from dual; exit; !SQL I think they are creating a new...

ssh issue in a loop

I have a script that connects to a server using ssh. While in a loop, it fails to connect to the second server after connecting to the first one. I guess I have to quit from that server to come back to the calling script. How do I quit the ssh session? while read dbname myip do ssh root@$myip "mysqldump - some command " | mysql -hhost -...

Why linux sort is not giving me desired results?

I have a file a.csv with contents similar to below a,b,c a ,aa, a a b, c, f a , b, c a b a b a,a,a a,a,a a aa ,a , t I am trying to sort it by using sort -k1 -t, a.csv But it is giving following results a,a,a a ,aa, a a aa ,a , t a b a b a,a,a a , b, c a,b,c a b, c, f Which is not the actual sort on 1st column. What am I doin...

How can I change spaces to underscores and lowercase everything?

I have a text file which contains: Cycle code Cycle month Cycle year Event type ID Event ID Network start time I want to change this text so that when ever there is a space, I want to replace it with a _. And after that, I want the characters to lower case letter like below: cycle_code cycle_month cycle_year event_type_id event_id ne...

Shell script help! Looping over directories under a directory

I want to write a shell script that loops through all directories under a directory, and call a java program with the directory name as an argument at each iteration. So my parent directory is provided as an argument to the shell script: eg: . myShell.sh /myFolder/myDirectory There are 100 directories under /myFolder/myDirectory. F...

How to find all files which are basically soft or hard links of other directories or files on linux?

How could I get the list of all linked files on my system or from a certain directory. I used to create links but they became unmanageable with time. I want the list of all such links from a directory. Can anyone help? ...

Shell scripting debug help - Iterating through files in a directory.

#!/bin/bash -f files = 'ls /myDir/myDir2/myDir3/' for file in $files do echo $file java myProg $file /another/directory/ done What i'm trying to do is iterate through every file name under /myDir/myDir2/myDir3/, then use that file name as the first argument in calling a java program (second argument is "/another/directory...

GUI Using Shell Batch File

I'm now going to develop a program that will generate Shell Batch Files(*.sh), but I want to know some things: It's possible to show GUIs using they? How to do this? ...

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...

How to show file download progress in PHP Shell Scripting?

Hiya, I have a php shell script that downloads a large file, it would be a bit of a luxury to be able to see the progress of the download in shell while it's happening, anyone have any idea how this can be achieved (or at least point me in the right direction!) Thanks! ...

How to read a directory name within a bash script

I'm extracting a tar file within a shell script and it is is creating folder with a name like: supportsuite-5-20-3/ The "supportsuite" part of the name is always the same, but I don't know what the remaining characters are in advance. I'm unpacking the tar file in a script and I need the name of the resulting folder from within that...

How do I insert a script variable into a regex string?

I'm writing a script that is trying to insert a directory name into a pax command and I'm not sure how to get the syntax correct. This is what I'm trying, but it seems to be treating the $DIRNAME as part of the regex string. DIRNAME=$(tar -tvf $1 | head -1 | sed -e 's:^.* \([^/]*\)/.*$:\1:') pax -r -f $1 -s'/$DIRNAME\/upload\///' ...

running shell script on low privileged user

Hi, I have a requirement to run a java jar on a low privilege user on linux. e.g. If I am currently logged in as a 'root' user and want to execute a shell script that should run with the privileges of a low privileged linux user like 'postix' user account. Is it possible? If yes, please post relevant references as I don't know how to...

looping 1, 2 and 3 numbers

supposed to be I have 3 filenames file-00 file-01 file-02 I'm trying to replicate those files to file-03, file-04, file-05...file-98, file-99, file-100 based on the original files. So in bash I do #!/bin/bash x=0 y=1 z=2 for i in $(seq 0 100); do cp file-00 file-$((x=x+2)); cp file-01 file-$((y=y+3)); cp file-02 file=...

Remove slash from the end of a variable

hi folks, the bash auto completion make a / at the end of a directory how i can strip this out? Thanks for hints. #!/bin/sh target=$1 function backup(){ date=`date "+%y%m%d_%H%M%S"` PWD=`pwd` path=$PWD/$target tar czf /tmp/$date$target.tar.gz $path } backup ...

Getting the last argument passed to a shell script

$1 is the first argument. $@ is all of them. How can I find the last argument passed to a shell script? ...

How can I write a startup script for Mac OS X?

I have created a jar file in java, and I want to make the application automatically start during system boot up. I found I have to write a shell script for that. What should be that shell script look like? Is there anything else I have to do to make an application automatically start at boot up? ...

How to get $this->translate('Content') => Content in a Textfile

I am looking for a shell script which scans a direcotry and all its subdirectories for .php and .phtml files. Within these files, I am looking for $this->translate('') statements (also $this->view->translate('')) and I want to save the content of these statements in a textfile. The problem is, that there are several different types of t...

Offset from GMT standard time

Does Unix store the offset of the machine from GMT internally? like for eg:india standard time is GMT + 5:30.is this 5:30 stored some where? i need this to use it in a script like below if[[ off is "some value"]] then some statements fi ...