Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

3
votes
2answers
102 views

Unatended script execution in ubuntu terminal

I have installed Ubuntu on a VMWare virtual machine. When I got to installing a VMWare tools, I have stumbled upon a simple question: If I execute a script (perl script in VMWare tools case), is ...
1
vote
1answer
969 views

Allow www-data to execute a a script

I am trying to execute a script that will read a file written by PHP. The problem is that the script opens and some other files (C-ISAM file based database) and i have no clue what permisions to give ...
8
votes
4answers
4k views

How do I handle switches in a shell script?

Are there some built-in tools that will recognize -x and --xxxx as switches, and not arguments, or do you have to go through all the input variables, test for dashes, and then parse the arguments ...
1
vote
2answers
3k views

Where should I put a script that needs to execute once when the user logs in graphically?

Using Gnome 3 on Fedora 15, where should I put a script that needs to execute once when the user logs in graphically?
11
votes
5answers
4k views

How can I use environment variables in my shebang?

I have a Python script that need to be run with a particular python installation. Is there a way to craft a shebang so that it runs with $FOO/bar/MyCustomPython?
2
votes
1answer
509 views

Default fedora 15 install, how do you get a network drive to mount after login?

I am running a default fedora 15 install. My goal is to have a couple of network drives get mounted right after the user logs in graphically (not via ssh). The script I want to execute is basically ...
3
votes
2answers
257 views

What is the bug with this script - using 'select' command to print menu in linux

OS - Linux 64-bit I am trying to implement a simple menu using select command. The script (for testing purposes) is as follows #!/bin/bash echo "*******************" PS3='Select an option and press ...
8
votes
4answers
2k views

How to prepend a license header recursively for all .h and .cpp files in a directory

I'm trying to add a license header to all header files and source files in a project directory using a for loop. This is not working, is there any other approach using sed?
11
votes
3answers
1k views

Are free shell accounts safe?

I am trying to identify how safe the free shell accounts provided by the likes of shellmix.com are. I have never used one myself but want to suggest it to someone interested in learning shell ...
3
votes
3answers
365 views

How to “rpm -i” a package only when an older version does not exist?

I wish to install some RPM packages from a shell script. I want to ensure that each package is indeed installed, but I do not want to update a package that would already have an older version ...
4
votes
2answers
92 views

Extracting queries from log file that do not include banned lines

I have a log file that looks something like the following: query1 startQuery query1 do something query1 do something else query2 startQuery query1 do something banned query2 do something query3 ...
5
votes
1answer
136 views

How would one detect if external command exists in a script?

Is there a way to detect if an external command exists (i.e. wget, svn)? More specifically today, i was trying to run one of my scripts i wrote and the person didn't have wget or svn installed. The ...
3
votes
3answers
338 views

Delete files in a directory which are also in another directory

I copied a directory using this: cp -r dir/ ../../ without thinking and realized that it copied the contents of dir instead of actually dir to the above directory. Now I have a mess of files I need ...
2
votes
1answer
534 views

How do I replace certain text with the respective line number using sed?

I have a file where certain (not all) lines look like so: Sequence: n I wish to replace n with the respective line number. How can I do it with sed?
4
votes
3answers
2k views

How to kill two or more processes with one kill command?

I am using the following command to kill one java process via shell script: pidof java|xargs kill -9 $1 What if the list of pidof output has more than one elements? How do I kill them both with ...
2
votes
3answers
461 views

variable concatenation not working?

I have a simple bash shell script which is driving me bonkers. All I want to do is run a command which returns a result which I will then use in another command. The result of the first command ...
2
votes
2answers
3k views

Is there any way I can obfuscate “.sh” shell script?

I'm running Ubuntu. I need to know any way to obfuscate .sh shell script file contents in order to make it very difficult to read. Any suggestion are welcome, including using online obfuscator.
1
vote
4answers
3k views

How to iterate over two sets of iterables in a shell script?

Usually when I write a shell script for a specific task, I just make a list of files like so: #/bin/sh read -d '' imagefiles <<EOF ./01/IMG0000.jpg ./01/IMG0001.jpg ./01/IMG0002.jpg ...
2
votes
2answers
8k views

Bash shell script to locate and remove substring within a filename

I am trying to write a bash shell script in Mac OS X 10.6 (which is called by an Automator Action) to rename TV show DVD rips that I have named badly over the years. I want to remove part of the text ...
4
votes
2answers
3k views

How to pipe md5 hash result in shell

I am looking for a simple way to pipe the result of md5sum into another command. Something like this: $echo -n 'test' | md5sum | ... My problem is that md5sum outputs not only the hash of the ...
5
votes
4answers
2k views

Allow users to run only specific binaries with root permissions/privileges

I would like to allow a specific user to be able to sudo /sbin/iptables only. I have a bash script which configures iptables. The problem is that configuring /sbin/iptables as sudoable is not enough ...
6
votes
5answers
2k views

How do I configure mutt to display the date header in my local time zone in the pager?

When I view a message in the pager mutt displays the time in the Date header in UTC rather than my local time zone. The index view displays the local time correctly. I found this old mailing list post ...
5
votes
2answers
2k views

Arg list too long error while using find

I have the find command as follows: find /jobs/logs/* -prune -name '*.log' -type f -mtime +1 | while read LOGFILE do echo $LOGFILE done This is failing due to the following ...
8
votes
2answers
673 views

Measuring time within a script

This thread shows how to measure the time it takes to run a script. In my case, I am interested in measuring time between two points within a script. Here is an example of how I would like to use ...
8
votes
6answers
884 views

Bash- detect init system

This may have more to do with detecting operating systems, but I specifically need the init system currently in use on the system. Fedora 15 now uses systemd, Ubuntu uses Upstart, while others use ...
1
vote
1answer
7k views

Execute a script automatically through pbrun?

There is a Unix environment named sftwrk01, uatwrk01, intwrk01 and some more I need to check the logs in each environment everyday by login in as below (through pbsu which is a wrapper for pbrun): ...
3
votes
2answers
4k views

Replace all occurrences of a character in a variable using korn script

Part of the Korn script I am writing requires that I replace all occurrences of the ' character with two occurrences (''). I am trying to log some SQL that I am generating in this script to a column ...
4
votes
2answers
273 views

Combine two commands in .bash_profile

In my .bash_profile file, I'd like to setup a single command alias that is two commands that execute one after another. The first command takes an argument from the command line and the second is ...
1
vote
1answer
778 views

Taking output of /dev/tty into a variable

I created a two backup scripts - one for files (filebackup.sh) and another for database (dbbackup.sh). filebackup.sh calls dbbackup.sh and stores the output in a variable. The output returned by ...
2
votes
2answers
774 views

creating simple command for sudo apt-get install?

I need to run these commands very often: sudo apt-get install <package> sudo apt-get remove <package> Can I make it simple like: install <package> remove <package> I ...
13
votes
2answers
752 views

running script with “. ” and with “source ”

I was wondering if the following two ways of running a bash script are equivalent? . ./myScript.sh source myScript.sh Are they both running the content of the script instead of running the script, ...
6
votes
1answer
127 views

Where can I find out how to write a shell script that is as portable as possible? [duplicate]

Possible Duplicate: Resources for portable shell programming I want to write a shell script that is intended for further distribution. So I'd like to write it in a way that is as portable ...
12
votes
2answers
1k views

How to safely pass variables to root-enabled scripts?

This question is totally general and not only applicable to my situation, but... I have a small busybox appliance where I want a non-root user to be able to execute a particular script with root ...
3
votes
1answer
292 views

Conditionally killing a process based on its output

I have a REPL (read-eval-print-loop) for the Clojure programming language listening on a network socket. I can send it code over the network and the code will be evaluated and the answer sent back to ...
1
vote
1answer
2k views

Get path of current script when executed through a symlink

I have a utility consisting of a couple directories with some bash scripts and supporting files that will be deployed to several machines possibly in a different directory on each machine. The ...
11
votes
4answers
14k views

How to delete a file on remote machine via SSH by using a Shell Script?

I am writing a Shell Script where I have to delete a file on a remote machine via a Shell Script. Flow manually: ssh username@domain.com .. then at domain: cd ./some/where rm some_file.war How ...
3
votes
1answer
745 views

Chinese characters instead of Latin being written to file

When I run sed like this and print to a console everything is fine: sed '/Q/{ s/Q//g r /Users/ericbrotto/Desktop/question.txt }' Commision.txt But when I do this and output t a file: sed '/Q/{ ...
1
vote
1answer
170 views

Do we need to chmod a shell script before it can be rsh

I tried to rsh a shell script from OpenVms to a Red Hat linux. It seems that it is not executed. I created the shell script in OpenVms and Ftp it to the linux. I then ls -la the folder in linux: ...
2
votes
3answers
629 views

regexp in ksh for extensions tgz, tar.tgz

I'm trying to get a regexp (in ksh) to identify files with only the following extensions: tgz, tar.gz, TGZ and TAR.GZ. I tried several but can't get them to work. I'm using this regexp to select only ...
0
votes
1answer
374 views

sudo here-document / concatenation? [duplicate]

Possible Duplicate: Redirecting stdout to a file you don't have write permission on I'm new i'm trying to learn shell scripting. Is there a way to force a concatenation and override ...
3
votes
2answers
252 views

pulling strings out of mixed file of strings and binary

I'm trying to get my nokia backup file into an acceptable vcard format. It has valid vcard strings that appear in between binary data. For example: !@#JUNKCHARACTERS!@#!@BEGIN:VCARD VERSION:2.1 ...
1
vote
2answers
5k views

What is the default shell for .sh in AIX?

I am fairly new to AIX machine. We would like to deploy some program into the AIX machine which is yet to come. We have a short experience in AIX machine and after login using putty, we felt the ...
4
votes
1answer
2k views

awk: forcing a return status?

This is a followup to my earlier question. I am validating the number of fields in /etc/passwd using this handy snippit. In the following example, the users 'fieldcount1' and 'fieldcount2' have the ...
9
votes
2answers
1k views

How can I delete all files in a folder that haven't been accessed in a certain amount of time?

I'd like to run a nightly cron job that deletes all the files in a folder that haven't been accessed in a week or more. What is the most efficient way to do this in bash?
1
vote
1answer
315 views

How to install a database dump via Shell Script?

I have a Mysql database dump. I want to install it with Hudson via a Shell Script to an external Linux machine. How can you take a Mysql script and run it inside a database on other machine? I know I ...
2
votes
1answer
236 views

reading input in sed

i'm new to shell scripting. I'm learning little by little. I'm more familiar with php which is working toward my disadvantage right now. Anyway, i'm writing a shell script and i read in input with ...
23
votes
3answers
947 views

Should I care about unnecessary cats?

A lot of command-line utilities can take their input either from a pipe or as a filename argument. For long shell scripts, I find starting the chain off with a cat makes it more readable, especially ...
3
votes
2answers
1k views

how to send email as well as display it out

i am trying to run a script with the output to be emailed and watched(monitored), i try using this code: this are the output: >emailmessage echo "output here" >>emailmessage ...
3
votes
2answers
466 views

How to specify -? option with GNU getopt

When parsing command line arguments with GNU getopt command, how do I (if possible) do recognize -? as another option? Is there a way to escape it in the opstring?
2
votes
3answers
11k views

How can I call other shell script like a subroutine?

How do I call an other shell script and wait for its completion? I want to pass input arguments and receive returning result code. And continue running rest of codes.