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
2k 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
175 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
87 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 ...
13
votes
3answers
1k 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
75 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
606 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.
9
votes
8answers
11k 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
441 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
7k 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
305 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
687 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
652 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
402 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 ...
7
votes
3answers
6k 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:
8
votes
1answer
1k 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 ...
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 ...
6
votes
3answers
3k 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
2k 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 ...
1
vote
1answer
190 views

Mass update of /etc/ldap.secret

I have a group of servers authenticating against an LDAP server. I would like to be able to periodically update the /etc/ldap.secret file with an updated secret. I've written a small script that reads ...
4
votes
1answer
3k views

How can I automatically restart gnome-shell coming out of suspend mode?

So, due to an issue with gnome-power-manager, gnome-shell, and my nvidia card, I'm left in the awkward position of coming out of suspension/sleep with my graphics broken. This problem resolves itself ...
3
votes
1answer
3k views

auto accepting rsa key in bash script

I have done a little googling and have not come up with a clear answer to this question. I was wondering if someone could help me out with this issue. Is there a way to auto accept any RSA key inside ...
0
votes
1answer
223 views

sudo nt passing after redirection operator [duplicate]

Possible Duplicate: sudo permission denied but su grants permission I am trying to echo a new value into a file using following command sudo echo 4096 > /proc/sys/fs/file-max The ...
7
votes
2answers
849 views

How to do a text replacement in a big folder hierarchy?

I want to search and replace some text in a large set of files excluding some instances. For each line, I want a prompt asking me if I need to replace that line or not. Something similar to vim's ...
8
votes
4answers
310 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 ...
4
votes
3answers
6k views

checking an argument to a bash script is a string of all digits

The Bash FAQ says If you're validating a simple "string of digits", you can do it with a glob: # Bash if [[ $foo = *[!0-9]* ]]; then echo "'$foo' has a non-digit somewhere in it" else echo ...
2
votes
3answers
482 views

Batch File Rename Using Mapping File

I have a large collection of image files, for example: a.png, b.png, c.png, etc If I have a file with mappings of filenames to numbers, like so (ignore the format, it could be anything): a=>1 ...
4
votes
2answers
767 views

bash script is trying to execute a variable

I have a very short Bash script, like this: variable="3 things" if $(echo $variable|grep "^[0-9]\{1,\}") #if $variable begins with [0-9] then echo $(echo $variable|sed 's/ .*$//') else echo ...
19
votes
5answers
823 views

shebang and path

Why does a shebang need a path? Wrong #!ruby Correct #!/usr/local/bin/ruby #!/usr/bin/env ruby The operating system should have the information regarding the path for a registered command, and ...
8
votes
1answer
432 views

Command to move a window to all desktops

I'd like to be able to move (pin) an existing window to all desktops using a scriptable command, rather than through the window menu. wmctrl -r <WIN> -t <DESK> will move a window to a ...
2
votes
1answer
211 views

starting from last line processed when processing log file several times

I am designing a logging and reporting system for a web application. Within the web application some events can happen ("user logged in", "user performed action X", etc..). I would like the ...
3
votes
4answers
1k views

Replacing text from a list of replacements. Added complication: backslashes

I have a file A that contains pairs of strings, one per line: \old1 \new1 \old2 \new2 ..... I would like to iterate over file A, and for each line perform the replacement (e.g. "\old1 -> \new1") ...
4
votes
2answers
496 views

Shell script printing the most visited directories

Is there a way to write a bash script with the following functionalities? Be launched when I press some key or key combination. (not so important requirement) Identify the 7 most visited directories ...
4
votes
2answers
746 views

find arcana: can't get pipe to work in -exec line

How do I pipe the results of a find through a sed to xform the stream, and then use that transformed stream as one of two arguments to a script? IE: find turns up file1.tiff (among others) sed ...
6
votes
3answers
4k views

How to run a script from another path, and know the script's path?

I need to run a script that access a file in the same path it is located. For example: I have the script in /home/me/folder/script.sh, and this script will access the file /home/me/folder/myfile. As ...
7
votes
6answers
13k views

How to run commands in batch mode over ssh?

How can I run commands in batch mode over ssh? That is, what is the ssh command's equivalent of sftp -b <filename> <hostname>? I have a set of commands which I wish to run across a set of ...
4
votes
3answers
479 views

Best directory for shared scripts

What is the conventional directory to keep shared scripts that might be used by more than one user? I've read through this overview of the standard file system hierarchy, but it doesn't seem to ...
4
votes
7answers
5k views

get numeric ASCII value for a character

I'm trying to write a shell script which asks for an ASCII character in the range A-Z or a-z and returns its equivalent numerical value. For example, the output might look like the following: ...
36
votes
8answers
52k views

Looping through files with spaces in the names?

I wrote the following script to diff the outputs of two directores with all the same files in them as such: #!/bin/bash for file in `find . -name "*.csv"` do echo "file = $file"; diff ...
3
votes
4answers
2k views

stty: : Invalid argument

I am telnet-ing into a Solaris machine and I'm getting the above error with my scripts. I realize this is a common problem, and the solution is to check for the line 'stty erase ^H' within my profile, ...
11
votes
6answers
4k views

What are good online resources for learning shell scripting? [closed]

I am a beginner to shell scripting. I have not yet hardly coded a single program, but I am interested in learning it completely. Can anyone suggest some good online resources which will guide me?
2
votes
2answers
821 views

How do I prevent expansion when I use a pattern as argument to a script?

I need a very simple script which does this: mogrify -resize $1x$2^ -gravity center -crop $1x$2+0+0 $3 so that I can call it in this way: cropresize.sh 110 110 *.png the problem is that the ...
0
votes
2answers
902 views

Why curl -O -C on mac fails to download

The following script works on Ubuntu, but not on Mac. Why? How to edit it so that it would work there too? #!/bin/sh v=1.1 test_file="Test10.java" jar_file="dp4j-$v-jar-with-dependencies.jar" curl ...
4
votes
4answers
5k views

Can IFS (Internal Field Separator) function as a single seperator for multiple consecutive delim chars?

Parsing an array using IFS with non-whites space values creates empty elements. Even using tr -s to shrink multiple delims to a single delim isn't enough. An example may explain the issue more ...
4
votes
4answers
688 views

How to make functions created in a bash script persist like those in .bashrc?

My .bashrc was getting a little long, so I decided to break it up into smaller files according to topic and then call these files from within .bashrc as so #my long .bashrc file bash .topic1rc bash ...
6
votes
4answers
2k views

Copy a File From One Zip to Another?

I have a file named 'sourceZip.zip' This file ('sourceZip.zip') contains two files: 'textFile.txt' 'binFile.bin' I also have a file named 'targetZip.zip' This file ('targetZip.zip') contains ...
5
votes
2answers
927 views

How does bash interpret the equal operator with no surrounding spaces in a conditional?

The following script does not behave as I would have expected. Adding spaces around the '=' in the conditional made it perform how I wanted, but it got me thinking, what is it actually doing inside ...
2
votes
1answer
913 views

Download and install latest deb package from github via terminal

I would like to download and install the latest .deb-package from github (https://github.com/elbersb/otr-verwaltung/downloads to be exact). How can I download the latest package (e.g. ...