shell-scripting

How do you use newgrp in a script then stay in that group when the script exits.

I am running a script on a solaris Box. specifically SunOS 5.7. I am not root. I am trying to execute a script similar to the following: newgrp thegroup << FOO source .login_stuff echo "hello world" FOO The Script runs. The problem is it returns back to the calling process which puts me in the old group wit...

how to use ssh to run shell script on a remote machine?

Hi, could you please suggest me how to run a shell script on remote machine? I have ssh configured on both machine A and B. My script is on machine A which will perform a task on machine B. Awaiting response! Will be great help for me. Regards, Arun ...

What's the best way to check that environment variables are set in Unix shellscript

I've got a few Unix shell scripts where I need to check that certain environment variables are set before I start doing stuff, so I do this sort of thing: if [ -z "$STATE" ]; then echo "Need to set STATE" exit 1 fi if [ -z "$DEST" ]; then echo "Need to set DEST" exit 1 fi which is a lot of typing. Is there a more el...

are there any commands that are usually used for comparing time in bash shell script?

this was for an old computer class project which I am over with and now am wondering if there was a better way of doing things . we used to program an appointment.sh program where I solved the comparing time using an algorithm which converts time to a certain number you can compare today and tomorrow and of course what happens is it c...

How do I redirect the output of an entire shell script within the script itself?

Is it possible to redirect all of the output of a Bourne shell script to somewhere, but with shell commands inside the script itself? Redirecting the output of a single command is easy, but I want something more like this: #!/bin/sh if [ ! -t 0 ]; then # redirect all of my output to a file here fi # rest of script... Meaning: if...

DotNet version of Windows Scripting Host

Good morning, I work in a small shop (only two of us) and we currently manage more .vbs scripts that we would like to (we would like to manage zero). One of the nice things about these scripts is that it's quick to make changes (as necessary) and go back to our day jobs. That's all nice and good until we decide that the job needs to...

Invoke gdb to automatically pass arguments to the program being debugged

Hi, I'd like to write a script that (under certain conditions) will execute gdb and automatically run some program X with some set of arguments Y. Once the program has finished executing the user should remain at gdb's prompt until s/he explicitly exits it. One way to do this would be to have the script output the run command plus arg...

How do I edit /etc/sudoers from a script?

I need to edit /etc/sudoers from a script to add/remove stuff from white lists. Assuming I have a command that would work on a normal file, how could I apply it to .etc/sudoers? Can I copy and modify it, then have visudo replace the original with the modified copy? By providing my own script in EDITOR? Or can I just use the same locks...

race condition in the common lock on file?

this is the standard approach to create locks using file system. For example, visudo uses it: [ -f ".lock" ] && exit 1 touch .lock # do something rm .lock 1) I'm confused, for there's a race condition, yet Linux uses it 2) is there a better way to lock on files from shell? 3) or do I have to use directories instead? Found solutio...

Best "official" scripting language for Windows programmers

Suppose there were several projects mostly maintained by smart interns, who eventually leave after a period of time. Scripts are used here and there in key parts, for example, to back up a database, rename it, zip it, move it over ssh, unzip it, and then to restore it with different settings. You know, the scripting stuff. The programmi...

How can I get my bash script to work?

My bash script doesn't work the way I want it to: #!/bin/bash total="0" count="0" #FILE="$1" This is the easier way for FILE in $* do # Start processing all processable files while read line do if [[ "$line" =~ ^Total ]]; then tmp=$(echo $line | cut -d':' -f2) count=$(expr $count + 1)...

sqlplus access and email access using shell script..

I am fairly beginner level at shell scripts and following are the details.. Am looking for the best way to fire sql queries and and carry out some logic based on that data. I've used the following snippet.. shellvariable=sqlplus $user/$passwd <<END select count(1) from table1; end EOF if[$shellvariable -ne 0] then <> fi Is there a be...

Breaking out of "tail -f" that's being read by a "while read" loop in HP-UX

Hi All, I'm trying to write a (sh -bourne shell) script that processes lines as they are written to a file. I'm attempting to do this by feeding the output of tail -f into a while read loop. This tactic seems to be proper based on my research in Google as well as this question dealing with a similar issue, but using bash. From what I...

How can I programatically analyze (and change) the configuration of IIS

I'm relatively new to the Windows Server world (coming from *nix land). I'm used to analyzing a web-server's configuration by grepping through an apache config file. Is there an equivalent file/group-of-files for IIS? Lacking that, is there an official scripting interface for IIS? ...

Using a loop to execute text file

I have redirected some valuable information into a text file. How can I execute each line of that text file in a loop? What im thinking is to double space my text file, then to use a loop to execute each line invidually. I'm hoping that when i double space the text file every string of commands will have their own line. For example, t...

BASH while read loop breaking early

I've been banging my head against for wall for a while with this one. I want to SSH into a set of machines and check whether they are available (accepting connections and not being used). I have created a small script, tssh, which does just that: #!/bin/bash host=$1 timeout=${2:-1} ssh -qo "ConnectTimeout $timeout" $host "[ \`who | c...

Shell script numbering lines in a file

I need to find a faster way to number lines in a file in a specific way using tools like awk and sed. I need the first character on each line to be numbered in this fashion: 1,2,3,1,2,3,1,2,3 etc. For example, if the input was this: line 1 line 2 line 3 line 4 line 5 line 6 line 7 The output needs to look like this: 1line 1 2line 2...

Using getopts within user-defined-function in bourne shell

Is it possible to pass command line arguments into a function from within a bourne script, in order to allow getopts to process them. The rest of my script is nicely packed into functions, but it's starting to look like I'll have to move the argument processing into the main logic. The following is how it's written now, but it doesn't ...

configure ip alias and route, deal with network unavailable

I need to write a script to set ip address/mask/broadcast as an alias on eth0:0 plus set the default gateway. This solution works: ifconfig eth0:0 <ip> netmask <mask> up ip route replace default via <ip> but sometimes the second call gets an error "network unavailable". Adding a sleep between them fixes it, but is unreliable. What i...

Database data upload design question

I'm looking for some design help here. I'm doing work for a client that requires me to store data about their tens of thousands of employees. The data is being given to me in Excel spreadsheets, one for each city/country in which they have offices. I have a database that contains a spreadsheets table and a data table. The data tabl...