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

learn more… | top users | synonyms (2)

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
671 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
868 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
776 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
772 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
743 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
744 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
627 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
369 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
251 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
314 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
230 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
943 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
464 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.
4
votes
1answer
255 views

Passing clicked links in rxvt to a script

I start my browser vimprobable in tabbed like so: "`tabbed -d > /tmp/tabbed.xid`; vimprobable2 -e `cat /tmp/tabbed.xid`" [1] I am then able to send all new instances of vimprobable to tabbed (and ...
1
vote
1answer
1k views

What does “sudo chown -R hadoop:hadoop hadoop” do?

I saw the following script, posted online, that was used during the hadoop installation process. sudo tar xzf hadoop-0.20.2.tar.gz sudo mv hadoop-0.20.2 hadoop sudo chown -R hadoop:hadoop ...
8
votes
2answers
3k views

Bash: run command2 if command1 fails

I want to do something like this: if cmd1 && cmd2 echo success else echo epic fail fi How should I do it?
2
votes
1answer
292 views

What's wrong with my bash script?

I am trying to utilize zenity in my simple ffmpeg-cut-mp3 script, but it hangs after the input into zenity :/ What's the matter with this? #! /bin/bash start=$(zenity --entry --title="CutMp3" ...
2
votes
2answers
7k views

Executing a shell command from PHP with shell_exec

Included in my thesis is to create an administration interface, in which an administrator can approve users whom have asked for access to use OpenNebula. Upon approval the users should be added to ...
8
votes
4answers
12k views

How to inject keystrokes via a shell script?

I'm trying to inject keystrokes into the input daemon so as to simulate typing from a Bash script. Is this possible, and if so, how can I make it happen?
8
votes
5answers
2k views

Bash CD up until in certain folder

I do a lot of work in Magento, and so do a lot of the people I work with, and it gets annoying to have to type: cd ../../../../../../ To only find you're still a few directories from your root ...
2
votes
2answers
3k views

Using sed to replace a line with many special characters?

I am writing a rather massive script for a project and one of the issues I am running into before I can complete it is using the sed command. I am trying to find a line that has (located in ...
4
votes
1answer
2k views

Debugging shell scripts: Syntax checking without executing

Is there some option I can give to just check the syntax of a [bash] shell script to check the syntax of it, but not actually execute anything nor cause any potential damage?
2
votes
2answers
645 views

Create a new file by removing the new line character at the end of file

I have a flat file which contains the following data records between H: and T:. H:20050427 HEADER RECORD 0000000 00000 000000000 123456 00 654321 DATARECORD 0000000 00000 000000000 123456 00 654321 ...
9
votes
1answer
6k views

File descriptors & shell scripting

I am having a very hard time understanding how does one use file descriptors in shell scripts. I know the basics such as exec 5 > /tmp/foo So fd 5 is attached to foo for writing. exec 6 < ...
27
votes
5answers
2k views

Better way of accepting variations of ‘Yes’ from a shell prompt

Usability testing of a shell script I wrote found that people had different expectations on how to answer a question that expected ‘yes’ as the answer. See variations in the below code example. ...
2
votes
2answers
162 views

Need a script that generates files from words within a single text files

I have the following scenario and my lack of linux knowledge doesn't help a lot. I have a text file that contains YML values, in the following matters: coolregion: min: {z: -99613.0, y: 45.0, x: ...
1
vote
2answers
627 views

writing a command transcript to file

Here is a script from Mercurial issue 2743. Call it mq.sh. I'm trying to get it to do the following things, on Debian squeeze. Echo commands + standard output + standard error to a file. Prefix with ...
7
votes
1answer
350 views

ftp and shebang

Is there a way to shebang-ify ftp and write small ftp scripts? For example: #!/usr/bin/ftp open 192.168.1.1 put *.gz quit Any thoughts?
18
votes
5answers
13k views

Split pages in pdf

I have a scanned pdf file which has scanned two pages on one virtual page (page in pdf file). The resolution is with good quality. The problem is I have to zoom when reading and drag from left to the ...
8
votes
4answers
301 views

Do you prefer bash scripts or aliases for shortcuts?

I have a ~/bin directory (which is on my PATH) where I store a lot of little 1 or 2 line scripts. Some of them just cd into a directory and run a command on a file, like vim or something. But I also ...
12
votes
6answers
4k views

Best way to follow a log and execute a command when some text appears in the log

I have a server log that outputs a specific line of text into its log file when the server is up. I want to execute a command once the server is up, and hence do something like the following: tail -f ...