A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.
54
votes
5answers
30k views
Allow setuid on shell scripts
The setuid permission bit tells Linux to run a program with the effective user id of the owner instead of the executor:
> cat setuid-test.c
#include <stdio.h>
#include <unistd.h>
int ...
33
votes
8answers
40k 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 ...
5
votes
3answers
5k 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=echo ztemp.xml |cut -f1 -d '.'
I get the error:
ztemp.xml is not a command
The value of var4 never gets ...
23
votes
6answers
5k 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?
7
votes
8answers
5k 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 ...
148
votes
22answers
74k 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 ...
4
votes
4answers
3k views
Check for Process if Same is Running
Is there a script or a way in linux that when I try to execute a shell script/process, if the same is running, it will prompt that same is running and will exit otherwise it will continue.
0
votes
1answer
915 views
/bin/sh: ./check-dependencies.pl: not found — but check-dependencies.pl exists!
I'm trying to build Moses, but when I run make I get the following output:
minakshi@minakshi-Vostro-3500:~/Desktop/working-dir/moses/scripts$ make release
# Compile the parts
make all
make[1]: ...
17
votes
8answers
6k views
Object-oriented shell for *nix
Preface: I love bash and have no intention of starting any sort of argument or holy-war, and hopefully this is not an extremely naive question.
This question is somewhat related to this post on ...
2
votes
2answers
229 views
Commands for determining level of usage of server
I am scripting a new program that will connect to a cluster of machines in a VM park, and hopefully check their level of usage.
The VM clients are a combination of RHEL and CentOS, and runs on ...
13
votes
7answers
26k views
Execute remote commands, completely detaching from the ssh connection
I have 2 computers, localpc and remoteserver.
I need localpc to execute some commands on remoteserver. One of the things it needs to do is start a backup script that runs for a number of hours. I ...
6
votes
3answers
4k 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
5answers
1k 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
5answers
719 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 ...
1
vote
1answer
471 views
script to automate scp in network
I have a network full of Linux machines. In this network, I have a user as user1 with the password as password in all the machines.
I have the following script to put files in the home directory of ...
7
votes
1answer
204 views
Parallel execution of bash script
I have a table URL_Experiment in my database (mySQL database). I have 2 million URL links in this table.
For each URL, I am checking if some particular text is present in the URL and updating the ...
2
votes
3answers
244 views
What is the difference between ./script and . ./script? [duplicate]
Possible Duplicate:
Using ‘.’ to execute files in bash
I was trying to figure out how to export my environmental via script instead of changing my .bashrc file.
I found this old useful ...
20
votes
1answer
801 views
How to implement a horizontal cat? [duplicate]
Standard cat concatenates files line by line (row by row, if you will). I find myself needing a horizontal cat command more and more often recently; i.e. a command that takes a list of files and ...
5
votes
2answers
732 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 ...
9
votes
3answers
631 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 ...
5
votes
3answers
4k views
History command inside bash script
I have been bashing my head to write a simple history script for the last two days. History is a shell-built in command I couldn't able to use that within a BASH script. So, Is there a way attain this ...
16
votes
3answers
2k views
Does the shebang determine the shell which runs the script?
This may be a silly question, but I ask it still. If I have declared a shebang
#!/bin/bash
in the beginning of my_shell_script.sh, so do I always have to invoke this script using bash
...
4
votes
3answers
952 views
Keep running a script via ssh
ssh can use to run remote commands.
ssh [email protected] 'long-script.sh'
I run a long script that will take a lot of time, but I want to close my computer and keep running the script in the remote ...
6
votes
2answers
2k views
List elements with spaces in zsh
I've been studying zsh scripting for all of 2 hours at this point and I've hit a wall. I want to go through a list of files that may have spaces in them. I'm open to completely different approaches ...
5
votes
2answers
951 views
How to tweet using terminal?
I would like to tweet a message using terminal.
I tried something like:
curl -u 'TwitterUsername':'TwitterPassword' -d status=”Your Message Here” https://twitter.com/statuses/update.xml
but seems ...
5
votes
2answers
2k views
Privoxy: blocking twitter, facebook and google outside of their domainslr
Related subject: blocking facebook.com outside facebook.com domain
This is from default.filter
#################################################################################
#
# shockwave-flash: ...
3
votes
4answers
5k views
Need a loop to sleep for a fraction of second
On my machine I need to execute a cycle that iterates 1 simple command that must have a delay expressed in fractions of second.
Let's say that I need:
to save a file with an increasing enumaration ...
1
vote
2answers
78 views
Changing user to root when connected to a linux server and copying files
My script is coded in a way that doesn't allow you to connect to a server directly by root. This code basically copies files a server to my computer and it works but I don't have access to many files ...
8
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?
4
votes
2answers
2k views
How to copy someone's else folders from public.me.com with a wget-like tool?
How can I copy a folder from http://public.me.com/ (a service related to iDisk, or MobileMe) to my local filesystem with a Unix tool (like wget, a command-line non-interactive tool)?
The problem is ...
2
votes
3answers
192 views
Remove spaces and headers from a dumped database table
I have dumped the database table data into a flat file and below is how the data looks like : (Kindly copy from below
;metier_code ;
;-------------------------;
(0 rows affected)
...
2
votes
2answers
399 views
How to copy multiple files but keep their extensions the same?
I am looping through a number of files, and $file represents the current file.
How can I make copies or renames and keep the extension the same for this current file?
e.g. if $file = x.jpg
How to ...
2
votes
2answers
3k views
Sed: replacing digits
I am trying to write some install scripts for when I install/upgrade Ubuntu. I'm having trouble with fixing logrotate.d:
/var/log/ufw.log
{
rotate 7
weekly
missingok
notifempty
compress
delaycompress
...
1
vote
4answers
146 views
renaming multiple files increment order
I have the following files
SSt12.precip.374.sub.climatology.ctl
SSt12.precip.2874.sub.climatology.ctl
SSt12.precip.3764.sub.climatology.ctl
SSt12.precip.6774.sub.climatology.ctl
I want to rename ...
1
vote
2answers
357 views
stdout , stderr and logging using the script command
I have remove.sh which contains:
rm -v test.tmp
And I have install.sh which contains:
script remove.log -c './remove.sh'
What can I do so that whether or not test.tmp exists, I don't see any rm ...
0
votes
1answer
85 views
How do you keep the password hidden when invoked during the su command?
This is the first time it has happened to me where I am using the su command and it actually displays the password on the terminal and doesn't stay hidden. Here is my code snippet:
sshpass -p ...
0
votes
0answers
27 views
convert many eps files in a single pdf or ps file using shell scriptI
I have SSt12.OLR.1.eps, SSt12.OLR.2.eps SSt12.OLR.3.eps SSt12.OLR.4.eps ......and covert these eps files into single pdf or post script file.
please suggest a shell script.
0
votes
2answers
115 views
Run a script at startup
I am using Ubuntu 14.04. I wrote a small script named trial. The contents of the script are as follows:
#!/bin/sh
SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
sh -c firefox
I copied the ...
0
votes
2answers
1k views
Need help to make rows into column with awk or sed
Recently, I look for scripts to take this:
This;
Is;
First;
Line;
and make it like:
This Is First Line
0
votes
2answers
219 views
Autentification on SSH connection in OneLine [duplicate]
Possible Duplicate:
Shell Script for logging into a ssh server
I need to connect via SSH to a remote server, however I must do this with out interactive mode and with out use Public keys ...
18
votes
3answers
6k views
What does it mean to have a $“dollarsign-prefixed string” in a script?
I just saw this in an init script:
echo $"Stopping Apache"
What is that dollar-sign for?
My research so far:
I found this in the bash manual:
extquote
If set, $'string' and ...
13
votes
7answers
8k 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 ...
7
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 ...
4
votes
1answer
1k 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 ...
4
votes
2answers
461 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 ...
3
votes
4answers
5k views
Backup of LVM2 logical volume
I'd like to make backup on external drive of LVM2 logical volume in dd manner.
Approach I consider is to
make lv on extranl drive with identical size
copy with dd
(Please let me know if you see ...
10
votes
4answers
7k views
Script to change current directory (cd, pwd)
I want to run a script to simply change the current working directory:
#!/bin/bash
cd web/www/project
But, after I run it, the current pwd remains unchanged! How can I do that?
6
votes
2answers
494 views
How does this find command using “find … -exec sh -c '…' sh {} +” work?
@StephaneChazelas posted the following solution to this Q&A: Having some trouble using “find -exec {} +”.
$ find . -iname "*.extension" -exec sh -c '
exec <command> "$@" <additional ...
6
votes
4answers
3k views
Parallel execution of a program on multiple files
I have a small script that loops through all files of a folder and executes a (usually long lasting) command. Basically it's
for file in ./folder/*;
do
./bin/myProgram $file > ./done/$file
...
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, ...