shell-scripting

Analysing a shell script

This would be part of a reverse-engineering project. To determine and document what a shell script (ksh, bash, sh) does, it is comfortable, if you have information about what other programs/scripts it calls. How could one automate this task? Do you know any program or framework that can parse a shell script? This way for instance, I co...

Shell Script Variable Quoting Problem

I have an sh script that contains the line $PHP_COMMAND -r 'echo get_include_path();' I can not edit this script, but I need the eventual command line to be (equivalent to) php -d include_path='/path/with spaces/dir' -r 'echo get_include_path();' How can I achieve this? Below is a script that demonstrates the problem. #!/bin/sh...

No username when Oracle Forms calls Solaris shell script

Our application has a couple of shell scripts that are called from web-based Oracle Forms 10g, running on multiple Solaris 10 servers. We've discovered recently that the shell scripts are not running with the full permissions of the OAS user account that runs the forms. I added a echo User is $USER command to one script to display the ...

${HTTPD-...} Perl syntax

Ok, I can't figure this out from reading Perl's documentation. I'm looking at the RHEL4 init script for Apache... What does this line of code do? httpd=${HTTPD-/usr/sbin/httpd} Why not just httpd=/usr/sbin/httpd? What's up with all the extra syntax? -Geoffrey Lee ...

creating a file downloading script with checksum verification

I want to create a shellscript that reads files from a .diz file, where information about various source files are stored, that are needed to compile a certain piece of software (imagemagick in this case). i am using Mac OSX Leopard 10.5 for this examples. Basically i want to have an easy way to maintain these .diz files that hold the ...

How to read using "read" from file descriptor 3 in bash script?

http://bash.cyberciti.biz/file-management/shell-script-to-simulate-unix-more-command/ #!/bin/bash # Write a shell script like a more command. It asks the user name, the # name of the file on command prompt and displays only the 15 lines of # the file at a time. # ------------------------------------------------------------------------- ...

Bash scripting problem

cat hosts.txt | while read h; do telnet $h; done When I run this, it telnets to first host which denies the connection but then exists instead of looping over the other hosts in the file. Why is it exiting the loop after the first host and how can I fix it? Thanks. ...

A "try" shell script

So, the idea is to have a script that tries to run a command, and if the command fails it shows up any warnings/errors. My try: $ cat try.sh #! /bin/sh tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/temp$$ trap 'rm -f $tempfile >/dev/null 2>&1' 0 trap 'exit 2' 1 2 3 15 echo "$@" if ! "$@" >$tempfile 2>&1; then cat $tempfile; fa...

pipe many outputs to same file at the same time?

Say i have a bash script: #!/bin/bash php ./listen.php 3001 3003 26 & php ./listen.php 3002 3004 120 & can i pipe all of them to same output log file at the same time without conflict? example: #!/bin/bash php ./listen.php 3001 3003 26 >/tmp/log 2>&1 & php ./listen.php 3002 3004 120 >/tmp/log 2>&1 & ...

Sorting List and Adding Together Amounts Shellscript

Hi, I have a list such as: 10,Car Tyres 8,Car Tyres 4,Wheels 18,Crowbars 5,Jacks 5,Jacks 8,Jacks The first number is quantity, second is item name. I need to get this list so that it only shows each item once and it adds together the quantity if the item appears more than once. The output of this working correctly would be: 18,Car ...

How to modfiy environment.rb through sh script? (i.e. modify line in file through script?)

I'm trying to write a sh script to make a rails apps, however due to different conflict, I need to modify my environment.rb file to comment out the rails version. So my question is how do I had '#' to line 8 of environment.rb? ...

Tell if a user has SUed in a shell script?

I have a script which executes a git-pull when I log in. The problem is, if I su to a different user and preserve my environment with an su -lp, the script gets run again and usually gets messed up for various reasons because I'm the wrong user. Is there a way to determine in a shell script whether or not I'm currently SUing? I'm looking...

Starting two mochiweb servers with a single script file

I have a basic web server that I generated from the mochiweb framework. To start it I use the start.sh script that the framework automatically generates. Everything works fine and the server starts up. Now I have one more mochiweb server that I want to start along with the first one. Again, this starts up perfectly standalone with its st...

How to handle non-printable ASCII character parameters?

I'm working on a project where we are dealing with importing/exporting data from database tables using ksh scripts and Perl scripts. We have an existing process to export data from a table to a file and it is then imported into another system. Here's the catch - the export process dumps out pipe delimited files while the system that is...

Combine Text Lines That Match Criteria, Linux/sed/awk?

Hi I have a file like the following: 1, cake:01351 12, bun:1063 scone:13581 biscuit:1931 14, jelly:1385 I need to convert it so that when a number is read at the start of a line it is combined with the line beneath it, but if there is no number at the start the line is left as is. This would be the output that I need: 1,cake:01351 12...

unix shell script to remove blank lines following opening brackets

Hi all, I need a (sed, awk) shell script or, even better, a vim command to remove any blank lines following a line with a single opening curly bracket: void func() { foo(); } void bar() { helloWorld(); } should become: void func() { foo(); } void bar() { helloWorld(); } Any thoughts? ...

How to pipe a here-document through a command and capture the result into a variable?

Right now this outputs the value I need on stdout. How can I capture it into a variable so I can use it in the rest of the script? Requirements: The script needs to be all in one file. I'd prefer not to write any temp files, if possible. . #!/bin/bash cat << EOF | xsltproc - ../pom.xml | tail -1 <?xml version="1.0"?> <xsl:stylesh...

Logical operators ("and", "or") in DOS batch

How would you implement logical operators in DOS Batch files? ...

/bin/sh: How to redirect from &3 to named pipe?

I have a background process read from named pipe. for example mkfifo /tmp/log.pipe ./myprog.sh < /tmp/log.pipe I want to use &3 instead of specify /tmp/log.pipe echo "aaa" >&3 but results similar to echo "aaa" > /tmp/log.pipe How can I redirect &3 to /tmp/log.pipe everytime. ...

Simple Shell Scripting Question

Hi, I am a newbie with shell scripting but just wanna quickly do something really simple. I have a testprogram that writes some results into a file "result". I wanna run the program three times and then store the results in an appropriate file with the name result1, result2, etc. I thought something along those lines will do the trick...