A shell script is a script written for the shell, or command line interpreter, of an operating system.
1
vote
2answers
101 views
How to parse options in a shell function to navigate multiple projects
I can use help with this bit of bash I am trying to write. The scripts purpose is to speed up my development while working with multiple projects.
I labeled the parts that I have questions about in ...
1
vote
0answers
68 views
How to make tcsh not insert whitespace in a command that spans multiple lines
Bash does not seem to insert whitespace but tcsh does.
Tcsh
bash-3.2.25$ tcsh -c 'echo $tcsh; echo A\
> B'
6.14.00
A B
Bash
bash-3.2.25$ bash -c 'echo A\
> B'
AB
How can I ask tcsh to not insert ...
1
vote
1answer
619 views
How to add header and footer to the flat file
I need to add a header and a footer to flat file - I just need to get values from the parameter like system date and report run date in the top line and for the footer I need to get the record count ...
2
votes
1answer
139 views
How to capture text formatting in bash?
The following shell script works but removes colored formatting generated by rspec:
#!/bin/bash
OUTPUT=`rspec`
echo "$OUTPUT"
How to preserve the colors?
1
vote
4answers
4k views
Splitting string by the first occurrence of a delimiter
I have a string in the next format
id;some text here with possible ; inside
and want to split it to 2 strings by first occurrence of the ;. So, it should be: id and some text here with possible ; ...
2
votes
1answer
602 views
Calling java from Bash: “Cannot execute binary file”
I have this simple Bash script:
#!/bin/bash
java -jar ClosureCompiler/compiler.jar --js ../src/typescript.js --js ../src/ts-compiler.js --js_output_file TSCompiler.js
I'm getting this error when I ...
1
vote
2answers
296 views
Print/Tee to console without passing output to pipe
Is there a way to print or tee one thing to the console and still pass something else through to the next pipe? Something like:
echo dog | printOrWhatnot "PUTTING MY THING DOWN" | sed 's/dog/cat/g' | ...
3
votes
1answer
131 views
Printing colored text using script
When I type below command in the shell I get the OUTPUT in green color.
Command
echo "\033[32mCONNECTING TO abpwrk\033[m";
Output(in green color)
CONNECTING TO abpwrk
But if I use the same ...
0
votes
0answers
97 views
Write a shell script to emulate the Id command of Prime which lists files and directories [closed]
Write a shell script to emulate the Id command of PRIME which lists files and directories. It list files first with a header FILES and then directories with a header DIRECTORIES. This command has ...
4
votes
2answers
185 views
Shell script to backup directories
I'm running eclipse on windows and would like to automatically backup my src direcories for all my projects. I installed cygwin and tried to make a simple backup script but I am having trouble ...
3
votes
3answers
262 views
What does exit do in an if block in a shell script?
I have a question regarding unix shell script.
Say if you do exit 1 in inner if: will it exit or will it still execute the outer if? The following is a dummy example.
if [ "$PASSWORD" == ...
2
votes
2answers
306 views
Parse apache logs to exclude IP ranges
I need to look for some requests in a huge pile of apache logs. My only requirement is this:
I need to only view the requests coming from any IP address that is NOT included in a list of 50 IP ranges ...
3
votes
2answers
189 views
Download from dynamically changing urls via script
I want to write a script to download all Walter Lewin lectures from this page in wmv format: http://videolectures.net/mit801f99_physics_classical_mechanics/
However the links to the wmv file for ...
3
votes
1answer
323 views
gnuplot shell variable substitution and arrays
I need to use shell variables in my gnuplot commands, for which I'm using the here document style. I also need to use loops inside the gnuplot code. Both these things are working.
Now -- I want to ...
1
vote
3answers
558 views
Shell script to become root
How can we write a shell script to become root?
That is I donot want to input the password at prompt it should be within the script itself. I was trying to make but failed to do so.Is it possible, if ...
2
votes
1answer
263 views
Parameretrize file descriptor number to open a tcp socket in shell script
I'm tried to parameretrize in a variable the file descriptor number to open a tcp socket using exec command but it failed. Only work correctly when file descriptor number is a constant. In the next ...
-1
votes
2answers
90 views
please help with my script [closed]
I need to write a simple homework script for my Unix 101 course.
I need to take a directory name from the user, and list how many things are in it.
For some reason it doesn't work and gets the next ...
2
votes
3answers
1k views
solaris 10 + display 2 lines after match by grep?
I want to match for example:
The string e1000g0 from the lltconfig -a list , and then to display the two lines after the string e1000g0
so I get only the lines:
Node 0 du1a : ...
0
votes
1answer
138 views
How to effectively use bash scripting (different cost reductive ways and good habits)? [closed]
This is one of the most perennially important questions. How to effectively script ? What are the bad ways and what are the good ways ? I know of some, which i will point out here. If anybody does ...
2
votes
1answer
777 views
Executing a script from Nagios event handler fails to run
I have Nagios running on a webserver. For this one Nagios service check in particular, if it fails, it will run a script. This script is triggered via Nagios event handlers.
Nagios event handler ...
7
votes
4answers
964 views
Executing user defined function in a find -exec call
I'm on Solaris 10 and I have tested the following with ksh (88), bash (3.00) and zsh (4.2.1).
The following code doesn't yield any result:
function foo {
echo "Hello World"
}
find somedir -exec ...
3
votes
2answers
297 views
Requesting user input while reading file line by line
For class I need to write a Bash script that will take the output from ispell and when I try and request user input inside the while loop it just saves the next line of the file as the user input.
...
1
vote
2answers
574 views
Is there an easy way to create a FreeBSD rc script?
I have a FreeBSD jail in which I run a server using the command:
/usr/sbin/daemon /path/to/script.py
At the moment I have to run this command every time I restart the machine and the jail starts. ...
1
vote
1answer
175 views
How to create script that toggles one value in synclient?
I use synclient touchpadoff=1 to disable touchpad and synclient touchpadoff=0 to enable touchpad.
$synclient | grep TouchpadOff
TouchpadOff = 1
I'd like to create script that will ...
1
vote
2answers
230 views
List info about files/directories with spaces
I am trying to use ls to get information about files and directories. My current command fails to properly get the name whenever a file/directory has a space.
I am using this to list all ...
3
votes
1answer
540 views
show the year while listing files in the current directory
I am working on a red hat server
I want to list the files in a way where the year when each was file created would appear in the Date
how is that possible ?
6
votes
3answers
288 views
shell scripts are still working without #!(sha-bang line)
I am new to shell scripts and many books have written that use #!(sha-bang) line in starting of the script to invoke the interpreter .And this will invoke a new shell for script and do the ...
3
votes
1answer
736 views
Identify the number of unique values and then the number of occurrences of those values in the file
I have a data file which contains 15000 lines, but only 400 unique values. I am looking for a way to identify the number of unique values and then the number of occurrences of those values in the ...
2
votes
1answer
458 views
How to debug csh scripts?
My lab uses csh scripts to run jobs. It is usually difficult for me to debug a shell script, so I'm wondering if there is a csh debugger I can use.
I know there are some flags like -x or -v that can ...
0
votes
2answers
662 views
How to change the working directory of invoking shell using a script? [duplicate]
Possible Duplicate:
changing current working dir with a script
I am trying to create few scripts that would change the working directory of the main shell/terminal. Not able to do so. I ...
5
votes
3answers
3k views
Find files which are created a certain time after or before a particular file was created
I need a shell script which finds files which are created 1 hour before or 1 hour after a particular file (test.txt) was created.
If I go with find -newer, that means I'd have to create a temporary ...
1
vote
1answer
328 views
How to manage getops argument assignation
This is my first question.
I'm trying to make a small script with options and I'm using getopts to do it. The weird thing is:
The argument don't get assigned to the variable or it always enter the ...
0
votes
1answer
238 views
seq - invalid floating point argument error
I have a file with many numbers, with each number on one line. My goal is to find the numbers that are missing.
I'm trying to generate the sequence of all the numbers with seq
start=$(head -1 ...
1
vote
2answers
507 views
BASH: Grouping files by name
I have over one million files. And I have to proceed over them.
My files' directory hierarchies just like below
source=/opt/output/renamed/
target=/opt/output/combine
send=/opt/output/send/combined
...
3
votes
6answers
173 views
Extracting help message from script itself
I want that my help message be extracted from the script itself.
#!/bin/bash
#
# foo - do things
# Author: John Doe <jhon@doe>
# ----------------------------------------------
# SYNOPSIS
# ...
4
votes
2answers
323 views
Get line number in a Bourne shell script
I'd like to be able to print the current line number in a shell script. I know about the $LINENO variable in Bash shells, but it doesn't seem to exist in Bourne shells. Is there any other variable ...
0
votes
1answer
354 views
Shell script to recursively grep data from certain files in the directory and return values to file [closed]
I am making a simple shell script which will minimize the time I spend in searching all directories under a parent directory and grep some things inside some files. Here's my script.
#!/bin/sh
...
3
votes
2answers
143 views
How do I set a script that it will run on start up in FreeBSD?
I am using FreeBSD 9 and I want to make a script that will check if an Ethernet cable is connected, and if so, connects to it. I want to set it so that it runs whenever the machine starts up, or ...
2
votes
1answer
281 views
Inserting a file into another file using sed
I want to insert the contents of file1 into file2 after a matching PATTERN. I want to do it only after the first occurrence of the PATTERN.
I would like to know the modification I need to make to ...
2
votes
1answer
206 views
Script to Read Videos and output information
I am working on a script that reads all folders inside a Movie folder and outputs the information for each video in a file.
The current one I have is this:
movies=0
rm movielist
for dir in Movies/*
...
0
votes
2answers
400 views
batch rename a few files [duplicate]
Possible Duplicate:
Batch renaming files
I have some files that I wish to rename in a single command. The files are names thus. I want the E S Posthumus bit removed from the names and also ...
1
vote
1answer
119 views
What is the canonical way to implement order independent options in bash scripts? [duplicate]
Possible Duplicate:
How do I handle switches in a shell script?
Most common shell commands allow the user to specify options in any random order. Positional Parameters like $1 as commonly ...
12
votes
2answers
2k views
Execute a command before shutdown
I want to execute a simple command just before the computer shuts down (timing is not essential).
For startup I can use /etc/rc.local - is there something similar for shutdown?
Note that I would ...
0
votes
2answers
1k views
linux + add 10 days to date and get new virtual date
I have Linux ( RH 5.3) machine
I need to add/calculate 10 days plus date so then I will get new date (expiration date))
for example
# date
Sun Sep 11 07:59:16 IST 2012
So I need to get
...
9
votes
2answers
909 views
How can I test for POSIX compliance for shell scripts?
Probably the main thing that this website has taught me so far is the importance of writing portable shell scripts.
Considering that POSIX is the closest thing to a common standard between all ...
4
votes
1answer
686 views
How to find out common elements between two files?
For an example, I have 2 files having following info:
File #1:
12
13
14
15
File #2:
12 1
13 2
14 2
15 6
16 7
17 8
Output File:
1
2
2
6
In the output file, I want only the second column ...
0
votes
0answers
35 views
How do I decide whether to make a command a shell script or an alias? [duplicate]
Possible Duplicate:
In Bash, when to alias, when to script, and when to write a function?
If I want to make a command like gsb that will expand to something like git show-branch -a | more ...
2
votes
3answers
291 views
Find word in sentence with Bourne Shell (sh)
I'm trying to determine if a particular word appears in a sentence using Bourne Shell (sh). For example:
#!/bin/bash
INPUT='Lorem ipsum dolor sit amet.'
if [[ "$INPUT" == *dolor* ]]
then
echo ...
4
votes
3answers
292 views
How to poll existence of a background script correctly
I have a problem with the following kind of script:
#!/bin/sh
long_running_script.sh &
while [ `pidof long_running_script.sh` ]
do
echo "."
sleep 1
done
The sript will ...
2
votes
1answer
302 views
How to get the PID from a spawned process in expect?
Example: In a shell script I open a SSH tunnel whit this:
/usr/bin/expect <<EOD
set timeout -1
spawn ssh -fNL localhost:1873:localhost:873 HOST
expect "*?assword:" { send "$SSHPASS\r"}
sleep 2
...