shell-scripting

Is there an explanation of the difference between export and typeset in combination with nested function calls in a korn shell program?

I have encountered an issue with ksh programs running differently on ksh88 & ksh93 wherein functions which call functions handle differently, variables declared with typeset and export. Here is an example program that highlights the difference: #!/bin/ksh # example.ksh: highlights differences between typeset and export on ksh93 functio...

why cygwin cron cannot find a file when cygwin ls can?

I got a cron job scheduled by using cygrunsrv and vixie's cron for cygwin. The job is a shell script that copies files from one directory to another and renames them. The script is in /home/martin/my/script/copy_files.sh. And the permission for the path is: drwxrwxrwt+ 1 martin root 0 2010-06-02 17:36 home drwxr-xr-x+ 1 martin...

input of while loop to come from output of `command`

#I used to have this, but I don't want to write to the disk # pcap="somefile.pcap" tcpdump -n -r $pcap > all.txt while read line; do ARRAY[$c]="$line" c=$((c+1)) done < all.txt The following fails to work. # I would prefer something like... # pcap="somefile.pcap" while read line; do ARRAY[$c]="$line" c=$((c+1)) done ...

What the most efficient way to grab the bibliograpy name from a latex file via unix shell commands?

I am trying to write a shell script that compiles a latex source. I wish to grab the name of the bibliography file which is contained in a command like: \bibliography{filename} I need to save "filename" to a shell variable. My solution to this (in tcsh) is dreadfully embarrassing: set bioliography=grep -v -E "[[:blank:]]*%[[:blank:]]*...

Shell scripting : Find file with the name 'error_log' and check sizes, remove if over a certain size

Hi guys, I am trying to create a shell script/command that find error_log files created by PHP, check their file sizes and remove them if over a certain size. I have only gotten as far as printing the files and file sizes with the code below for i in `locate -r 'error_log$'`;do echo "$i|" `stat -c %s $i`;done Can anyone help? Thank...

Help with variables and new lines, and quoting in a bash script

I would like to automate the following svn command. Note this command produces the desired results on my system - Ubuntu 10.04, svn 1.6.6, bash shell, when issued from the command line: svn ci -m $'Added new File: newFile.txt\nOrig loc: /etc/networking/newFile.txt' /home/user/svnDir/newFile.txt I would like to run that command in a ba...

Can I use what I wrote on the shell (bash, cmd, irb, etc) in a script automaticaly?

The general idea is pretty simple, I want to make a script for a certain task, I do it in the shell (any shell), and then I want to copy the commands I have used. If I copy all the stuff in the window, then I have a lot of stuff to delete and to correct. (and is not easy to copy from shell) Resume: I want to take all the things I wrote...

deleting all the file of certain size

i have bunch of log files and I have to delete the files of some small sizes, which were erroneous files that got created. ( 63bytes ). I have to copy only those files which have data in it . ...

Running shell scripts with sudo through my web app

I have some functionality that interfaces with the server's OS in my web application. I've written a bash script and am able to run it from within my app. However, some functionality of the script requires superuser privileges. What is the most sane way to run this script securely? It is being passed arguments from a web form, but shou...

Shell Scripting For loop Syntax Error

Hello, I am trying to make a simple shell script to ping a source but I am getting bash-2.03$ ./test.sh google.com 10 .5 /home/users/me 16 256 ./test.sh: line 35: syntax error near unexpected token `((' ./test.sh: line 35: `for (( i = 1 ; i <= $totalArguments ; i++ ))' This is the code: #!/bin/bash ip=$1 count=$2 interval=$3 outputD...

How to add the number of active netstat connections of different machine?

I've written this code to get the connections from one machine and adding them with the number of connection of the other machine. This code is not giving any netstat, 0 is coming for the live active connections. #!/usr/bin/ksh -xvf Machine_Detail="prpm@sp204|LC1_R11_LCP|LC1_R12_LCP|LC1_FR15_LCP|LC1_R16_LCP prpm1@sp2048|LC1_R13...

Regarding Shell variable

I need to call another shell script testarg.sh within my main script. This script testarg.sh has arguments ARG1 ,ARG2, ARG3. I need to call up the below way: ./testarg.sh -ARG1 <value> -ARG2 <value> -ARG3 ARG1 and ARG3 arguments are mandatory ones. If it's not passed to the main script then I quit. ARG2 is an optional one. If the ...

Regarding PID Shell Script

I am calling another shell script testarg.sh within my main script. the logfiles of testarg.sh are stored in $CUSTLOGS in the below format testarg.DDMONYY.PID.log example: testarg.09Jun10.21165.log In the main script after the testarg process gets completed i need to grep the log file for the text "ERROR" and "COMPLETED SUCCESSFULLY...

Check for messages apache Qpid

Is it possible to check for messages from Qpid queue from unix/windows console? Here is how I check via GUI : http://i47.tinypic.com/pbu5d.gif I can see all the info from Qpid JMX Management Console, is there a something close to this that I can use in console? ...

for loop range not working ksh

I tried this, #!/bin/ksh for i in {1..10} do echo "Welcome $i times" done in Ksh of an AIX box. I am getting the output as, Welcome {1..10} times What's wrong here? Isn't it supposed to print from 1 to 10?. Edit: According to perkolator's post, from http://stackoverflow.com/questions/1591109/ksh-iterate-through-a-range It wor...

echo value inside a variable ?

x=102 y=x means when i echo $y it gives x echo $y x --and not 102 and when i echo $x it give 102 lets say I dnt know what is inside y and i want the value of x to be echoed with using y someting like this a=`echo $(echo $y)` echo $a Ans 102 ...

grep value inside a variable pointing to other variable

using : ksh *abc = 1 efg = 2 hgd = 3 not known to me * say if i have Value="abc efg hgd" abc efg hgd all contains some value which i dnt know. Now I want to grep the value contained inside abc. like for i in $Value do grep "echo $(($((echo $i | cut -d'|' -f2))))" done this grep should look for the value...

Playing Chess via SMS Messaging

I know there are some pretty nice open-source chess engines with powerful AI, like Crafty, that also have a nifty command line interface. I also know that I can send e-mails with my SMS-capable phone, and that I can reply to such an e-mail, and it will be sent to my phone as a SMS text message. Is there any way I can combine the two? ...

How does the #! work?

In a script you must include a #! on the first line followed by the path to the program that will execute the script (e.g.: sh, perl). As far as I know though, the # character denotes the start of a comment and that line is supposed to be ignored by the program executing the script. It would seem though, that this first line is at some p...

Randomly selecting lines from files

I have bunch of files and very file has a header of 5 lines. In the rest of the file, pair of line form an entry. I need to randomly select entry from these files. How can i select random files and random entry(pair of line, excluding header) ? ...