A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.
3
votes
7answers
624 views
Write a remote managing script
I need to be able to locally run a script that will connect to various servers and run commands on them. What is the best way to accomplish this?
22
votes
5answers
3k views
What Unix commands can be used as a semaphore/lock?
I want to run multiple Bash shell scripts in parallel. However, I want to avoid race conditions. What Unix commands are truly atomic that I could use for this purpose, and how can I use them?
8
votes
6answers
496 views
Best way run a command on each file in a directory tree
There appear be a number of ways to do this including loops in shell script, find and xargs. Which of these is best, and which is most portable?
2
votes
2answers
193 views
/usr/bin/env: zsh -: No such file or directory
I get the error
/usr/bin/env: zsh -: No such file or directory
...when I run an executable zsh script that starts with the following shebang line:
#!/usr/bin/env zsh -
Also, FWIW, replacing - ...
1
vote
1answer
94 views
How to clone a read-only portion of /proc file system
The problem with reading /proc file system is that it is not atomic. I tried using a library (procfs in Python) that wishes to read it, but it has glitches about 5% of the time because the process ...
2
votes
3answers
65 views
Scripting to domain allocation to server
I have two text files:
file #1: domain.txt
cocacola.com
airtel.com
pepsi.com
file #2: servers.txt
192.0.53.42 , 4 # 4 domains already allocated on server 192.0.53.42
192.53.1.2 , 1 # 1 ...
5
votes
4answers
200 views
Hybrid code in shell scripts. Sharing variables
This answer discusses how to run a multi-line Python snippet from the command line in a terminal. I noticed that the answer works great within shell scripts, even with nested indentation, which is ...
0
votes
1answer
98 views
Counting files on a remote server with ssh and an expect script
Below is my script to take count for files which are present in remote server.
But it is not working. Please help me.
#!/usr/bin/expect
spawn ssh sduser@172.0.0.2
expect "123"
send "123"
interact
...
0
votes
2answers
57 views
Executing a program according to the last modified date
I need to write a script which would execute some executables in a directory according to the last modified date. The oldest should run first. How do I do it?
This is what I have done so far
for f ...
2
votes
2answers
549 views
If Statement with 2 Variables - Bash
I am trying to write a single IF statement which can check two variables at once.
I have two variables, for example:
$VARA
$VARB
Both with either contain a 0 or a non 0 value. I need an if ...
92
votes
16answers
41k views
Repeat a Unix command every x seconds forever
There's a builtin Unix command repeat whose first argument is the number of times to repeat a command, where the command (with any arguments) is specified by the remaining arguments to repeat. For ...
1
vote
2answers
61 views
Direct recursive shell script output to each subdirectory, not parent directory
I'm processing a batch of subjects data recursively, calling the script within the parent directory.
For example, I have the parent directory:
/home/subjects
and the subdirectories which contain ...
4
votes
3answers
77 views
CD into directory from HISTORY in a bash script or alias e.g. $(!!)
I often want to change into the directory of a file on my file system, but I'm not sure where the file is.
I search for it like so:
find -type f -name "myfile.txt"
Lets say for the sake of ...
2
votes
1answer
49 views
Invoking a script with ld-linux.so?
I just downloaded a tar file that is supposed to include everything required to run a program that we can call some_binary. I extracted it's contents, and I see the following:
A binary (let's call ...
2
votes
1answer
134 views
Script to check a folder, print the files then delete those files
I am looking for some guidance on creating a script that will check a specific folder, print all documents (if any) and then delete those documents. I would also like to run this script as a cron job. ...
2
votes
4answers
840 views
cut / grep and df -h
How can I grep or cut the "173G" under "Verf"?
I need this for Unix scripting in school.
jonas@jonaspc:~/$ df -h /dev/sda2
Dateisystem Größe Benutzt Verf. Verw% Eingehängt auf
/dev/sda2 ...
0
votes
1answer
71 views
How to get the arguments to a php function via grep?
I am writing a script to let me know the database login info for each PHP-based web site on a server that I am migrating. The login information is usually done either like this:
...
5
votes
3answers
2k views
Storing output of command in shell variable
I have an operation using cut that I would like to assign result to a variable
var4=ztemp.xml |cut -f1 -d '.'
I get the error:
ztemp.xml is not a command
The value of var4 never gets ...
1
vote
0answers
28 views
rsstail Not Printing Output
I've installed rsstail 1.8 on my linux box and everything seems to be going smoothly, knock on wood, except for the part where rsstail isn't printing the streams. Running the command, I see that it's ...
2
votes
2answers
84 views
What scripting language can I use to automate a concatenation & zipping process?
For a project I'm doing I need to concatenate and compress (with zip) many (midi) files and compare their sizes. I've thought there must be some language that allows me to do something like this:
...
1
vote
3answers
323 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
...
1
vote
4answers
515 views
Checking if a file exists in several directories
I've been working on this far too long and need some help.
I need a script that will look at files in a directory and see if it exists in one of several directories.
I need something like this:
for ...
2
votes
1answer
44 views
Bash: pair up two series of files
I have a number of files with this pattern:
file1_foo.ext
file1_bar.ext
file2_foo.ext
file2_bar.ext
and so on.
I need to "pair them" and put them in a file like this
file1_foo.txt ...
2
votes
4answers
116 views
store and execute redirection/piped command in script
How do you store, and later execute, a command with redirection and and a pipe? (And is it the pipe, or the redirection, or both, that's causing my problem?)
I tried to print the urxvt version in a ...
4
votes
1answer
224 views
Increase %e precision with /usr/bin/time shell command
When I run the time command in shell time ./myapp I get an output like the following:
real 0m0.668s
user 0m0.112s
sys 0m0.028s
However,when I run the command \time -f %e ./myapp I lose ...
0
votes
2answers
188 views
Ubuntu crontab php not working
Yes, I have read many, many documentations but I can't get it to work. I have a simple single php file which I want to run once or twice in a minute. My php file is called: cronjob_refresh.php and I'm ...
0
votes
2answers
187 views
Automated ssh-keygen without passphrase, how?
I would like to make an automated script that calls ssh-keygen and creates some pub/private keypairs that I will use later on. In principle everything works fine with....
ssh-keygen -b 2048 -t rsa -f ...
2
votes
1answer
51 views
How would a script know when running locale-gen is necessary?
One of the basic steps in setting up a new system is getting the right glibc locale files generated. At least in ArchLinux and Gentoo, one is expected to do this step by hand. I am trying to setup a ...
5
votes
3answers
3k views
Processing bash variable with sed
Been banging my head off a wall on this
bash variable LATLNG contains a latitude & longitude value in brackets like so
(53.3096,-6.28396)
I want to parse these into a variable called LAT and ...
3
votes
1answer
43 views
How to edit files in-place while performing operation on the values matching the searched pattern?
Given a list files containing random text and many datetimes in ISO format in it (e.g "2012-07-02T10:47:24+02:00"), how can I find all these datetimes and add 2 hours to each one ?
Ideally a solution ...
3
votes
3answers
186 views
Split PDF into documents with several pages each
There are several resources on the web explaining how one can split a PDF into many files with on page per file.
But how can you split them into chunks of, say, five pages each? I have looked into ...
11
votes
1answer
1k views
Making a progressbar with “dialog” from rsync output
I'm looking for a way to filter/redirect rsync output in a manner where it can be fed to the "dialog --gauge" command, so I can get a nice looking progressbar during file sync.
Currently I have only ...
1
vote
1answer
127 views
Securely reading and parsing a string from a parameter or file in bash
I've been writing a number of bash scripts lately which get variables from a parameter or from a file. Some of the scripts run as root (using sudo)
This is on my notebook, so there aren't any other ...
3
votes
1answer
103 views
Searching for Failed attemps in /var/log/secure
I'm currently writing a script to examine /var/log/secure file and report how many failed attempts there were that day. I need to output it in the following format:
Date: 03/15/10 Time: 10:30 Number ...
0
votes
1answer
221 views
How can I find and filter a specific column in a .csv file? [duplicate]
I have .csv files with the following structure:
cat,dog,mouse,pig,bird,cow,...
21,34,54,566,78,1,...
23,10,12,569,56,4,...
32,20,13,123,56,3,...
34,30,44,322,66,2,...
I want to filter the column ...
13
votes
7answers
4k views
Faster way than ping for checking if computer online?
I'm writing a wake on lan script for a set of our lab computers. We have sqlite db with a list of the computer hostnames, IPs, and MACs and currently I ping each of them with '-c1' so it doesn't run ...
1
vote
4answers
108 views
Where to put a background script
I have a script that i want to be constantly running in the background but I don't know where to launch it from
If I put it in .bashrc it will run multiple times (one for each login)
It's an ...
1
vote
1answer
40 views
Sort aligned columns
I have a program which output looks like this
# Status VAL1 VAL2 Description
1 some text 2.5 4.4 Some long other text
5 some text 2 14.5 2.0 Some long other ...
7
votes
1answer
250 views
Problems running python script from motion
I'm trying to set up the raspberry pi with my webcam as a motion detecting cctv that uploads the videos to google drive using Jeremy Blythe's script
I have motion working correctly and the python ...
0
votes
0answers
44 views
A simple script to make a desktop version of Nimbuzz WebChat? [closed]
There is a nice little script which uses python-webkit called "RGB/HEX Color Picker" here: http://gnome-look.org/content/show.php?action=content&content=128317
I tried if I can use it to make a ...
8
votes
1answer
445 views
python == python2 OR python == python3 ? How to package, distribute python py2k scripts?
Depending on system, python==python2 or python==python3.
Executable Python scripts, starts with:
#!/usr/bin/env python
#!/usr/bin/env python2
#!/usr/bin/env python3...
For python py3k it is ...
2
votes
1answer
322 views
Create sub-directories and organize files by date
I have some directories of files copied from my security camera that I would like to organize into sub-directories by file date. So for example;
-rwxrwxrwx 0 root root 4935241 Jul 19 2012 ...
1
vote
2answers
124 views
find total ram memory and swap memory
I need to write a script to find total memory and total swap of several linux server (2000+).
I have one trusted server from where I can login to all these 2000 servers without a password.
When I run ...
6
votes
5answers
524 views
How can I have more than one possibility in a script's shebang line?
I'm in a bit of an interesting situation where I have a Python script that can theoretically be run by a variety of users with a variety of environments (and PATHs) and on a variety of Linux systems. ...
6
votes
3answers
333 views
Universal Node.js shebang?
Node.js is very popular these days and I've been writing some scripts on it. Unfortunately, compatibility is a problem. Officially, the Node.js interpreter is supposed to be called node, but Debian, ...
0
votes
0answers
22 views
How do I comment parts of a multiline command? [duplicate]
In bash command line or scrip invocation, a command could run several liens long. In this case, delimiting the lines with \ is useful.
What I am trying to make work is:
command \
-option1 ...
0
votes
1answer
126 views
ipset not executing from crontab
I have this txt files that contains IPs, one per line of file, that I want to block using ipset.
I have this bash script that essentially reads from the plain txt file and constructs an array. Then ...
1
vote
2answers
172 views
At login, take picture of user at Login window(loginGUI promt window)
I have code to take a picture in a script. I don't understand how to run this script at the time of login. I would like to modify the login process so that:
The user gets 3 login attempts.
After 3 ...
3
votes
3answers
95 views
Where are userspace programs supposed to save their logs?
I am writing a script that I want to run without privileges. I want the errors that the script encounters to be logged to some log file. I do not not have privileges to write one to /var/log. And I do ...
4
votes
4answers
216 views
List any file ending with .in and corresponding .out with shell script
I have a directory full of files ending with different extensions, how would I list/select only the files ending with .in and corresponding .out that share the same basename?
e.g.
file1.txt
file1.in
...




