A shell script is a script written for the shell, or command line interpreter, of an operating system.
2
votes
2answers
529 views
How can I retain the console input in mplayer when reading from stdin?
I'm playing around with the command line interface of mplayer. I'd like to script it in the following way
find /some/path/ -type f | grep -vif blacklist | mplayer -shuffle -playlist -
where ...
3
votes
2answers
491 views
Fix or alternative for mktemp in OS X
I'm looking at a bash script someone else wrote that uses mktemp:
TEMP=`mktemp --directory`
However, this line does not work on my machine (OS X 10.6).
How would I fix this line so that it is ...
4
votes
3answers
1k views
Get lines with maximum values in the column using awk, uniq and sort
I have a file with next format
2011-12-01 user1 access1
2011-12-01 user1 access2
2011-12-01 user2 access2
2011-12-01 user4 access2
2011-12-02 user1 access1
2012-01-01 user3 access1
2012-01-01 user4 ...
10
votes
3answers
1k views
How to properly collect an array of lines in zsh
I thought the following would group the output of my_command in an array of lines:
IFS='\n' array_of_lines=$(my_command);
so that $array_of_lines[1] would refer to the first line in the output of ...
32
votes
4answers
3k views
Why is it better to use “#!/usr/bin/env NAME” instead of “#!/path/to/NAME” as my shebang?
I notice that some scripts which I have acquired from others have the shebang #!/path/to/NAME while others (using the same tool, NAME) have the shebang #!/usr/bin/env NAME.
Both seem to work ...
3
votes
3answers
262 views
How to make svn look for if there is an update once a minute and if there is call some script?
I am developing a server app. I have a remote machine with Debian that I use for testing. Currently I update the server manually when each new svn version comes out. It is just a testing server and ...
2
votes
3answers
651 views
Keep running a script via ssh
ssh can use to run remote commands.
ssh me@server.com '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 ...
2
votes
3answers
483 views
Killing other user processes
There are certain user environments in which we have to login during certain performance testing and and kill all the process running in that environment.
The environment names are like rswrk01, … up ...
2
votes
3answers
2k views
How to search and replace text in all php-files in a directory and it's subdirectories
I am looking for a shell script that recursively traverses all .php files in a directory and performs a search & replace of a particular text pattern.
The search pattern is quite long ( > 5000 ...
5
votes
1answer
300 views
How to find out how many cores (including emulated via HT and such) are avaliable to user?
I wonder how to get how many cores (including emulated via HT and such) are avaliable to user via bash shell-script command?
5
votes
1answer
568 views
Running cron script with lynx fails to work
I'm trying to automate a login process that can only be done through a browser. I am using the lynx browser to script the actions required to do this. Lynx does this by dumping a user's keystrokes ...
3
votes
1answer
1k views
Bash: Merge foldername from variable with filename
First I write a configfile with all my parameters like this
path="/home/test/"
I name it test.conf.
Then I write a shell script with this content, name it test, and make it executable with chmod ...
4
votes
2answers
275 views
Can I trace a dash script without modifying its source code?
I would like to trace a shell script for debugging purposes without having to modify its source code (e.g. change the shebang or insert a set -x at the beginning). It is a dpkg postinst script, so not ...
5
votes
3answers
668 views
killing processes automatically
I need to kill all processs in a certain shell excluding certain processes.
Like sh which is my shell. And the comand.
This is what currently in my shell right now.
rcihp146 :/home/msingh2> ps
...
2
votes
5answers
251 views
Bash script that can test for a particular lib
I'm writing a bash script that needs to test if certain libs are installed on a VPS, and if they're not, the script will install them.
My problem is being able to have the script determine if they ...
2
votes
1answer
213 views
How to parse the file from end in awk
#!/bin/sh
if [ $# -ne 8 ]; then
echo "Usage: sh `basename $0` YYYYMMDD hour min masterid account destination filename forward|backward";
exit 1;
fi
day=${1}
hour=${2}
min=${3}
...
3
votes
1answer
111 views
'find' across directories named …/dirnameXX/… with XX variable
I am executing this command to find certain files in specific directory:
find ./rgs/test/maesXX/master/stdlist -name \*.extract \
-mtime +30 \! -size 0 -exec ls -lrt {} \;
where XX could be ...
4
votes
6answers
2k views
How can I convert tab delimited data to comma delimited data?
I'm requesting a list of ec2 snapshots via amazon's ec2 command line tool:
ec2-describe-snapshots -H --hide-tags > snapshots.csv
The data looks something like this:
SnapshotId VolumeId ...
1
vote
1answer
333 views
Script that unpacks a initrd, allows editing of the preseed.cfg and the packs it to cpio and gzip again
I want to program a script that allows what is said in the title. So basically I gunzip the initrd, than unpack the cpio, open vi to allow editing, save, pack with cpio, and gzip again, so nothing ...
1
vote
4answers
1k views
script to scan ip range and return results in a certain format
This script scans IP's and returns a status of Up or Down. How can I alter it so it doesn't scan everything twice? As it sits it scans everything and returns the "Up" addresses only and then scans all ...
2
votes
4answers
336 views
Is there any handy command line tool to manage Cron jobs?
Would someone suggest any handy command line (NOT web) tool or script which adds, enables and disables Cron jobs? I am looking, for example, for the following (or similar) behavior:
sh manageCron.sh ...
1
vote
1answer
336 views
Power broker safe shell or full shell script
I am looking for a script which we can pass as an argument to the pbrun command.
Eg:
Login: test1
Passwd: xxxxxxx
Welcome to Solaris 10 gcmsys01
$ pbrun sysadmins safeksh
Here sysadmins is the ...
1
vote
3answers
389 views
Why is the following script not working?
I wrote the following script for finding the number of pdf and tex files from the current directory, including the subdirectories and hidden files. The following code is able to find the number of pdf ...
2
votes
2answers
171 views
Why does “$i | sed” not work?
I have this code:
if [ $i | sed -e "s/^.*\(.\)$/\1/" = "/" ]
then
echo "folder"
else
echo "file"
fi
where $i is something like this
app4/
The code above should get the last char of the ...
-2
votes
1answer
196 views
Why does this script show all files in the directory and not just PDF files?
I wrote the script below to find the number of PDF files in a given directory. However, it instead shows all the files in the directory:
#!bin/bash
message="."
message1="*.pdf"
ls -al $message ...
3
votes
1answer
390 views
wait for autossh connection to complete
I'm trying to create a script that runs a few commands that take a long time to execute and require a constant connection, but
autossh user@server
wait $! #or wait ${!}
commandA
commandB
doesn't ...
8
votes
3answers
2k views
How can I receive top-like CPU statistics from the shell?
I'm trying to get an accurate read of my used CPU (in percent) from top. This is the command I'm running for testing:
top -n1 | awk '/Cpu\(s\):/ {print $2}'
This returns:
10.7%us,
Which is the ...
2
votes
1answer
1k views
Script to SCP files works manually but not through cron
I'm using CentOS 5.6. The below code might have some typos as I needed to change real info to fake info for security reasons:
backup.sh
#!/bin/bash
set -vx
rm -v /server/temp_db.gz
rm -v ...
1
vote
2answers
713 views
Using rsync in a cronjob when a password is needed
Basically I have a bash script that fetches data from my server to perform a backup.
As it is now I have to start that script manually, enter the password, and then wait for it to finish.
I would ...
1
vote
1answer
240 views
Reading two files into an IFS while loop — Is there a way to get a zero diff result in this case?
I have a text file full of several hundred lines of sequences like this:
b 29.
b 52.
c 84.
c 83.
c 94.
c 93.
c 61.
b 38.
c 81.
c 92.
c 28.
c 37.
...
0
votes
1answer
497 views
Shell script to merge properties file (sed/awk/comm/diff) for rpm upgrade
We're developing a java product that's installed via rpm.
We have a set of config files that a user can edit. These config files are java properties files in the form:
com.acme.pkg1.setting=something ...
3
votes
2answers
691 views
Set alignment of numeric columns when columnating data
I use column -t to format data for easy viewing in the shell, but there seems to be no option to specify column alignment (e.g. align to the right).
Any Bash one-liners to do it? I have arbitrary ...
6
votes
4answers
3k views
How to read from two input files using while loop
I wanted to know if there is any way of reading from two input files in a nested while loop one line at a time. For example, lets say I have two files FileA and FileB.
FileA:
[jaypal:~/Temp] cat ...
-1
votes
2answers
2k views
Wait for process to finish before going to the next line in shell script
I have a script I made to create a backup. I need to make sure the backup is ready before it runs the /home/ftp.sh command. How can I do so? I use CentOS 5.6
#!/bin/bash
tar -Pcf ...
2
votes
3answers
257 views
How does setting the Setuid bit affect shell scripts that run on boot of the system, before any login has occurred?
Would enabling the setuid bit on a shell script make a difference at all when that script is run on boot? Who would the effective user be?
6
votes
1answer
339 views
What is wrong with this shell script?
The service for a piece of software I just installed (from a provided .deb file) on a Ubuntu server won't start. When running the service I get the error:
/etc/init.d/matrixsa: 44: Syntax error: "}" ...
4
votes
3answers
4k views
How to set global environment variables at boot through a script, and have them available for an application that runs before login?
I have a service that runs at boot, and in that service it calls a bash script in the background that exports some environment variables. The problem I'm having is that those environment variables ...
2
votes
4answers
732 views
Parallelizing a for loop with very large number of iterations
I want to parallelize a for loop where the number of iterations in the loop can be very large such as 10^6. So ,it will be better if I can create threads rather than process. How to do it? The code is ...
7
votes
2answers
1k views
Parallelizing a for loop
I want to parallelize the for loops of the following code. How to do this?
#!/bin/bash
N=$1
n=$2
for (( i=1; i<=$N; i++ )); do
min=100000000000000 //set min to some garbage value
for (( ...
5
votes
1answer
4k views
How to check if there are no parameters provided to a command?
How do you check if $* is empty? In other words, how to check if there were no arguments provided to a command?
3
votes
2answers
81 views
dealing with un-executable commands inside a shell-script
I am given an assignment like this: Write a Bash script that takes a *.tex file as command-line argument and checks if the file executes correctly without any errors. If it executes without any error ...
-1
votes
2answers
1k views
clear tmpfs in my case
I am on a Ubuntu machine.
I have make a directory under root directory, by:
$ sudo mkdir /hello
$ sudo mkdir /hello/bye
Then I mount tmpfs with size 1024M to /hello/bye by:
$ sudo echo "tmpfs ...
2
votes
2answers
194 views
How do I prevent a script from terminating when the shell exits?
In particular, I created a script to start Firefox which I double-click and choose 'Run in terminal,' but when the shell exits Firefox is killed immediately.
How do I prevent this from happening?
3
votes
2answers
343 views
Simple shell script needed to move database files
I am using MySQL on Ubuntu machine.
I need to physically move around the database files under /var/lib/mysql/ (this is where all the databases directories are located).
Say I have two databases, ...
0
votes
2answers
135 views
getting file name from the input path to the file in shell scripts [duplicate]
Possible Duplicate:
Best way to remove file extension from a string?
Say that I have a script called script.sh
In the shell I type
script.sh ../folder/file.py
and in that file I know ...
2
votes
5answers
371 views
How to find out if PWD contains spaces or non-English letters?
I created an environment variable:
WD=`pwd`
How can I check if it contains spaces or non-English letters?
4
votes
4answers
1k views
How to perform a sed in-place substitution that only creates backups of files that were changed?
I ran the following to replace a term used in all files in the current working directory:
$ find . -type f -print0 | xargs -0 sed -i'.bup' -e's/Ms. Johnson/Mrs. Melbin/g'
This performed the word ...
5
votes
2answers
388 views
How enable safeguards for CPU temperature
My desktop has a nasty habit. When I have several high intensity applications running and my CPU is at maximum usage for a period of time, the core temperature rises and my computer auto-shuts off.
...
1
vote
3answers
165 views
Returning a portion of a line matching a pattern
I have a file (file_name) which contains exactly one occurrance of the string "Result: " at the start of a line. I want to print all the characters after the string "Result: " in that line until I ...
10
votes
5answers
3k views
How to compare to floating point number in a shell script
I want to compare two floating point numbers in a shell script. The following code is not working:
#!/bin/bash
min=12.45
val=10.35
if (( $val < $min )) ; then
min=$val
fi
echo $min