A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.

learn more… | top users | synonyms (1)

3
votes
1answer
984 views

How to use a value returned by a script in grep filter?

I'm on FreeBSD's csh. I want to form a row with domains of one user and then use this row to filter exim maillog to get only mail from/to this user's domains. I wrote a script to form a row from a ...
8
votes
2answers
5k views

Invert boolean variable

I want to try simple script flag=false while !$flag do read x if [ "$x" -eq "true" ] then flag=true fi echo "${x} : ${flag}" done But when i run it, if i type true, i will see ...
2
votes
2answers
319 views

add “check if fetchmail is running” to this script

while ! postqueue -p | grep -q empty; do sleep 1 done killall wvdial this script checks if my mail queue is empty, then disconnects my modem. now i would like to add also a checking to fetchmail ...
1
vote
3answers
549 views

To list out duplicate filenames in a listing?

bash-3.00$ cat f.txt -rw-r--r-- 1 mukesh other 102 Nov 5 18:32 f1.txt -rw-r--r-- 1 mukesh other 19 Nov 5 18:32 f2.txt -rw-r--r-- 1 mukesh other 204 Nov 5 18:32 ...
17
votes
3answers
5k views

How do I exit a script in a conditional statement?

I'm writing a bash script where I want to exit if the user is not root. The conditional works fine, but the script does not exit. [[ `id -u` == 0 ]] || (echo "Must be root to run script"; exit) ...
2
votes
2answers
809 views

Ignoring files that find cannnot search or open?

I searched for big files using this command on HP Unix: find . -type f -size +100000000c -exec ls -lrt {} \; The result came out somthing like this: -rw-rw-rw- 1 qa1wrk32 test 169263642 ...
9
votes
3answers
596 views

How to pipe the list of commands displayed by of “tab complete”?

When using commands in bash I like the double tab option to display the available commands. Some commands have more possible matches than others: Is there a way I can pipe the output of the double ...
0
votes
1answer
388 views

Making a simple PHP script process text in a pipe

Last week I wanted to convert some simplified Chinese characters into traditional ones. I found a deceptively nice looking shell one-liner, which today I found out was 20% error prone. So I did some ...
5
votes
3answers
483 views

What does the syntax on this shell command with extglob mean?

In Building paths robustly, A solution is proposed that includes: shopt -s extglob; dir="${dir//+(\/)//}" Can someone explain (parse) that for me? I understand what it's doing, but not how the ...
1
vote
3answers
257 views

ksh cannot cp from location with space in it?

I am trying to do the following in ksh but keep getting cannot stat message for the cp command: JMX_ROOT=/bfs-build/build-info/mep_mainline-Linux.latest/core/mainline/automation ...
1
vote
1answer
884 views

Concatenate multiple strings with spaces in them?

I am trying to do the following in ksh shell: JMX_ROOT=/bfs-build/build-info/mep_mainline-Linux.latest/core/mainline/automation SMOKE_JMX_LOCATION="$JMX_ROOT/\"Smoke Set\"/*.txt $JMX_ROOT/\"Smoke ...
7
votes
3answers
3k views

How to “send” variable to sub-shell?

I run the following script: VAR="Test" sh -c 'echo "Hello $VAR"' But I get : # ./test.sh Hello How can I "send" the variable VAR of my script to the shell created with sh -c?
2
votes
2answers
3k views

How to exclude a list of full directory paths in find command on Solaris

(Duplicated from Stack Overflow: http://stackoverflow.com/questions/7854975/how-to-exclude-a-list-of-full-directory-paths-in-find-command-on-solaris) I have a very specific need to find unowned files ...
2
votes
1answer
107 views

Start and stop multiple executable for easy debugging

I'm debugging a networking project, which involves interacting of 3 programs, ie a server, two different clients. However I find it difficult to start and stop them for debugging. Some methods I have ...
4
votes
5answers
6k views

Match regex in ksh

I am looking to do something like this in KSH: if (( $var = (foo|bar)[0-9]*$ )); then print "variable matched regex" fi Is it possible at all? For the record I'm using Ksh Version M-11/16/88i ...
1
vote
2answers
161 views

How to log if an environment variable is unset? [closed]

How can I write a shell script that checks for an environment variable and writes to a log file if the variable is unset? Also, if the file name pointed by env variable doesn't exist, how to create ...
1
vote
3answers
374 views

Evalute passed in variable in bash

Is there a way to pass in a variable as an argument to a bash script and have it evaluated scoped by the bash script? Given: # cat /path/to/file/of/host/names bob tom joe etc... # dofor FILE=$1 ...
3
votes
3answers
3k views

How to watch rss feed for new entries from bash script?

I need to watch a RSS feed from our hudson ci server. Each time a new entry is available i want to play a sound by calling #>play sound.wav. Does anyone know a tool which can watch a rss-feed and ...
5
votes
4answers
946 views

Last failed command in bash

The $? variable holds the exit status of last run command. Is there a variable that holds last run command itself?
1
vote
3answers
292 views

tail -f equivalent

I am seeing several seconds delay with the tail command. I found the cause for it has something to do with nfs services. I am using arch linux and yet to find out how to disable all these services I ...
6
votes
2answers
1k views

bash: Piping for loop output prevents local variable modification

First off, sorry for the title. I'm not sure of the correct terminology so if anyone can improve upon it that would be good. I am trying to write a simple bash function that takes, as it's arguments, ...
6
votes
5answers
613 views

Shell programming, avoiding tempfiles

I often write KSH shell scripts that follow the same pattern: (1) retrieve output from one or more command (2) format it using grep|cut|awk|sed and print it to the screen or to a file In order to ...
4
votes
1answer
348 views

Alternatives to XDialog

Are there any alternatives to XDialog? Ideally something that would support both X server and terminal interface.
1
vote
2answers
713 views

How can I queue processes?

I have a surveillance camera and a program records videos when motion is detected. Basically, this program saves the video in a very heavy format. My solution was to call a script that converts the ...
5
votes
1answer
654 views

Automated incremental backups to an external drive

Background A client needs an automated backup solution to an external drive (to be taken offsite weekly). I'd typically suggest rsnapshot (or perhaps rolling out a custom rsync script), but this ...
2
votes
2answers
304 views

Comparing files and their properties

I get information of a certain set of files in my mail every day, which looks like this: 58623208 Sep 14 20:08 blbn_blfbe_drv 57904920 Sep 14 19:54 blbn_cycmn 55814208 Sep 14 06:02 clsa_Upd 38912000 ...
2
votes
1answer
930 views

shorthand for feeding contents of multiple files to the stdin of a script

Hi good people of this community, Say I have a script called script, that reads from stdin and spits out some results to the screen. If I wanted to feed it contents of one file, I would have typed: ...
4
votes
2answers
359 views

Should I be using 'sudo' in scripts that I write?

I'm setting up a new machine (well actually, an Ubuntu VM) and am trying to write a script to setup a few common things that I use when doing this (Git, curl, vim + janus). So my script looks a bit ...
2
votes
3answers
1k views

How can I test if a program is running from within a script

Let's assume that another user started a bunzip process, and I have a script that I'd like to start running after that bunzip finishes. What's the best way to check from inside my script that the ...
2
votes
1answer
1k views

How can I use imagemagick's identify command in a script to tell if a JPEG file is invalid or corrupt?

I have a somewhat-kludgey script in which I want to copy valid, complete JPEG files to a photo album directory. I thought I could use ImageMagick's identify command to do this. The web documentation ...
3
votes
1answer
160 views

Help improving my AWK skills

This program works as I intended but I feel like I used some clumsy methods to get the out put I desired(especially with my use of print commands and variable declarations) Could some one improve ...
2
votes
2answers
80 views

How do I execute a command on a given string in each line of a file?

Let's assume that I already have a file created. This file creation comes from the execution of a command. The contents of the file will be up to 4 different lines looking something like this: LUN ...
12
votes
3answers
846 views

How to make those old-school GUIs (like the debian/arch installer)

I've been doing a lot of installs lately, and when possible I usually opt for the text install from the Live CD's GRUB menu. Most installers looks like this: I always thought these GUIs (if you can ...
3
votes
2answers
62 views

Text files with sections in common with a given file

I need to maintain a set of plain text files saved in a directory which all have a section taken from another file. An example follows: Files: /directory/textfile1 (every other file in the directory ...
2
votes
1answer
429 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
2answers
1k views

What does `export COLUMNS` do?

What is the significance of importance of the command export COLUMNS ? What I know is that it's a global variable. I frequently see it in the beginning of *nix scripts.
6
votes
8answers
3k views

Automatically run commands over SSH on many servers

There is a list of IP addresses in a .txt file, ex.: 1.1.1.1 2.2.2.2 3.3.3.3 Behind every IP address there is a server, and on every server there is an sshd running on port 22. Not every server is ...
2
votes
1answer
328 views

vim script: how to change “put =” to an append?

I'm trying to hack the c-vim plugin because I don't like the way it inserts comments. I want this: /* comment */ but it gives me this: /* comment */ I'm sure it has its reasons, but I don't ...
4
votes
2answers
2k views

Problem while running “newgrp” command in script

I want to change the working group in my script. So I wrote a line newgrp test_grp1 in my script. But my script is automatically exited after running this line. Are there any solution to overcome this ...
12
votes
3answers
5k views

Answer yes in a bash script

I'm trying to do a git clone trough a bash script, but the first time that I run the script and the server is not known yet the script fails. I have something like this: yes | git clone ...
4
votes
4answers
262 views

Generating sets of files that fit on a given media size for tar -T

Can anyone suggest a script that will take as input the name of one or more directories and a media size, and output lists of files for input to tar using -T (assuming no compression)? ...
3
votes
1answer
499 views

Make a failed SSH forward a fatal error

I have a script which connects to a remote host to replicate some files via SSH. I must connect to an rsync daemon listening on port 873. To accomplish this I have a ssh configuration like this. ...
3
votes
1answer
555 views

Change screen “hardstatus” color dynamically

I show the hard-disk free space in hardstatus screen. But also I want change the color of this value when it's less than a value to alert me. I have done a script that it checks this and it returns a ...
2
votes
2answers
238 views

Want a seperate file to store mysql username, password, and database name

I have as script that dumps a mysql database, and compresses the file. What I want to do is have another (edit) file which can change the username, password and database name. Then somehow connecting ...
6
votes
3answers
3k views

What is IFS in context of for looping?

I'm learning bash scripting right now. I was reading this thread: How to loop over the lines of a file? What is IFS? With for and IFS:
7
votes
1answer
937 views

confirmed exit using trap

I am trying to trap the Ctrl+C signal asking a confirmation from the user. The trapping part works fine. But once the signal gets trapped, it does not return to the normal execution. Instead, it quits ...
0
votes
1answer
978 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 ...
5
votes
3answers
2k views

The way to use `/usr/bin/env sed -f ` in shebang?

Typing /usr/bin/env sed -f in terminal works. But if use it as a shebang, #!/usr/bin/env sed -f s/a/b/ The script will be fail to execute: /usr/bin/env: sed -f: No such file or directory I ...
1
vote
3answers
1k views

Is it possible to execute a VIM script in a non-interactive mode?

The Gnats bug tracker has a command (edit-pr) that opens a ticket in $EDITOR. My $EDITOR is VIM, and when this command opens the ticket in $EDITOR, I'd like to automatically perform some scripted ...
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 ...