A shell script is a script written for the shell, or command line interpreter, of an operating system.
3
votes
1answer
25 views
What do use the -t “tag” option for in logger?
When using the "logger" command to write messages to the system logs from scripts, I use the -t "tag" to store the scripts name along side the message it's written to the log.
I do this to make ...
3
votes
2answers
27 views
Portable way to get script's absolute path?
What is a portable way for a (zsh) script to determine its absolute path?
On Linux I use something like
mypath=$(readlink -f $0)
...but this is not portable. (E.g., readlink on darwin does not ...
5
votes
2answers
81 views
Walking through files in directory randomly
How to change for track in *.mp3; do so that all .mp3 files in the current directory are walked through but in a random way?
3
votes
1answer
39 views
Can't indent heredoc to match nesting's indent
If there's a "First World Problems" for scripting, this would be it. Mainly asking because I feel like I should know how to get around it if I need to.
I have the following code in a script I'm ...
1
vote
1answer
37 views
get free string genre id3-tag and not only genre number in bash script
I'd like to read the id3-genre tag within a bash script.
I tried id3tool, eyeD3, etc -- but these tools just support the genre number. How to get the free string genre tag?
My music players (Amarok, ...
0
votes
2answers
39 views
`ps | grep | kill` aborts my script prematurely [duplicate]
I have a Linux computer that I remotely SSH into using plink on a Windows XP machine. I have the Plink program set to execute commands in a script using automated login:
plink -ssh [domain name] -l ...
1
vote
3answers
68 views
Setting file permissions in bash script
This script is not working the way I thought it would .I though it would find all the scripts that have every one rwx permissions changed to the permissions of xx5
#!/bin/bash
# the / makes find ...
1
vote
2answers
39 views
How do I capture the return status and use tee at the same time in korn shell? [duplicate]
Consider Source code:
1. Parent.sh
#!/usr/bin/ksh
# No tee
ksh Child.sh;
exit_status=$?;
echo "Exit status: ${exit_status}"
# Using tee
ksh Child.sh | tee -a log.txt;
exit_status=$?;
echo "Exit ...
2
votes
4answers
58 views
Perform floating point arithmetic in shell script variable definitions
I understand bash and some other interpreters only perform arithmetic for integers. In the following for loop, how can I accomplish this? I've read that bc can be used but am not sure how to use bc ...
3
votes
3answers
34 views
Print process ID (PID) of a Matlab instance
To run my Matlab scripts, I've created a shell script to which I give two parameters - the path to the matlab file ($1) and to the log file ($2):
nohup time matlab -some_parameters -r "run $1;exit" ...
-1
votes
0answers
31 views
The logic behind implementation of getopt and programms like getopt [closed]
I would like to know the general logic behind the implementation of getopt kind of functionality, so that any script would have optional parameters or some options or parameters could be must for that ...
4
votes
4answers
106 views
sed how to substitute when string has “http://” in it?
I have a file xx that has the following contents:
@base_url = "http://dmstaffing-stage.herokuapp.com/"
I want to use sed to eliminate this line (replace with nothing). I have used this sed ...
0
votes
2answers
39 views
Unable to copy that prior version to newer version
# in bash
shopt -s extglob
cd /oc/txa/db/
dirs=$(echo $(ls [1-9]*([0-9])_[0-9] | sort -rn | head -n 2))
# if there are no other files and directories you can use "ls |" in the line above
...
-3
votes
2answers
49 views
How to change the environment from /usr/bin/ksh to bash [closed]
How to change the environment from /usr/bin/ksh to bash
#!/usr/bin/ksh # in bash
7
votes
1answer
135 views
“w | tail” chops text at right margin (78 characters)
Summary: w | tail chops rows after 78th column.
When I run the "w" command, it works as expected. However, when I pipe the output to "tail", it chops the output to 78 columns wide (truncates anything ...
-3
votes
0answers
39 views
How to Run the SAS program in shell script automatically [closed]
How to Run the SAS program in shell script
/data/tx/16_0/mq.sas.
0
votes
2answers
66 views
How to create as many variables as needed from shell script(bash)?
I'm making a script for monitoring some user processes with Upstart but, since its for the company I work for, they asked me to do it generic...how's so?
Well, the number of processes being monitored ...
3
votes
3answers
63 views
checking data in columns when a data or some may be missing or present?
I am not sure if this possible.
say i have columns like :
Team Colour Game Rainfall PlayerName
XYZ Blue Cricket Yes Kapil
suppose i need to search ...
-1
votes
1answer
53 views
copy sas file from prior version directory to new version directory [duplicate]
How to copy sas file from prior version directory to new version directory in unix script-automatically?
Here prior version = 15_1
Newer version = 16_0
/data/temp/15_1/
-rwxr-x--- 2 ...
13
votes
1answer
263 views
Can bash case statements cascade?
I'm trying to do something like this:
case $level in
3)
echo "Level Three"
2)
echo "Level Two"
1)
echo "Level one"
;;
esac
where if $level = 3, it ...
-1
votes
0answers
52 views
How to touch a multifile using ssh? [closed]
I am trying to touch a file to another server as follows:
ssh [user]@[server] '. /abinitio/apps30/abinitio30.env m_touch path_to_mfs way'
It is giving error as:
Cannot create recovery file in ...
4
votes
3answers
72 views
Why is sed giving me an error about an unterminated `s'?
I have a set of sed replacements in a bash script and am getting an error about an unterminated `s' command. Here's what the sed line looks like:
sed -n -e "s/TMPFOO1/$FOO1/" -e "s/TMPFOO2/$FOO2/" ...
4
votes
4answers
112 views
Can I write the output the of time difference command to a file?
Can I write the output of the time difference command to a file?
For example, I tried:
$ time foo.sh > bar.txt
But it only gives the output of foo.sh to bar.txt.
1
vote
3answers
37 views
Solaris: Script for finding the physical device path of all installed fiber cards
I have a number of systems (with quite varying type, generation and architecture unfortunately).
I need to create a list of fiber cards on these varying systems.
I am able to use prtconf -v, and ...
-4
votes
1answer
58 views
How to copy datasets from prior version directory to latest version directory [closed]
I've go a number of directories named like:
/data/db/OX/8_10
/data/db/OX/9_1
/data/db/OX/9_2
And need to copy some files (all the pt.* files) from the second latest one (above 9_1) to the latest ...
1
vote
1answer
64 views
How can I test whether the output from a command is null or empty string? [closed]
I'm trying to get a pre-commit hook script to work on our old SVN box.
It's very old, running Ubuntu Server 8.04.
This script:
@echo off
::
:: Stops commits that have empty log messages.
...
2
votes
1answer
72 views
What does “${x%% *}” mean in sh? [duplicate]
I just saw "$${x%% *}" in a makefile, which means "${x%% *}" in sh.
Why it is written in this way ?
how can a makefile detect whether a command is available in the local machine?
determine_sum = \
...
3
votes
2answers
83 views
Clarification regarding behavior of shell script along with pipe
I need help understanding the behaviour of the following shell script.
#!/bin/bash
echo "First more"
more $1
echo "First echo"
echo $1
echo "Second more"
more $1
When I run the following command:
...
-4
votes
0answers
56 views
How to copy sas files from prior version directory to new version directory. [closed]
How to copy sas files from prior version directory to new version directory automaticaly
-8
votes
0answers
73 views
How to copy datasets automaticaly [closed]
How to copy datasets automatically from one directory latest version to another directory
1
vote
2answers
80 views
shell script to do some text manipulation of text file data structure and slight content changes
Apologies in advance for the wall of text, not sure how else to represent the existing data structure.
I have been handed about a years worth of logs collected every hour from a server.
Sadly, ...
1
vote
2answers
56 views
How to make sure the shell builtin echo is invoked so that its not visible in process list?
Is this going to be visible in the process listing if the below line is executed from a command line or a shell script
bash -c "echo $password"
or
i just need to do echo $password from within ...
6
votes
2answers
116 views
Decode Flags for Kill Command
I am new to Shell Scripting.
I saw this Command on a Book for Linux shell Scripting
$ kill -HUP 1234 >killout.txt 2>killerr.txt
I know what the command does, but i am not able to understand ...
2
votes
2answers
60 views
Including sub-parameters in help options to execute wisely without getopt or getopts?
I am writing a script which can choose a file and print specific content. For example,
san#./script.sh
Expected Usage : ./script.sh --file1 --dns
(Here it checks for file1, search for dns name and ...
-4
votes
0answers
69 views
how to pick higer version directory automatically and make directory on that higher version [closed]
Write a autoscript to identify the latest version of the two folder. And pick that higher version of the folders and make a directory for that higher version under the second folder.
0
votes
1answer
48 views
Can I redirect output to a log file and background a process at the same time?
Can I redirect output to a log file and background a process at the same time?
In other words, can I do something like this?
nohup java -jar myProgram.jar 2>$1 > output.log &
Or, is that ...
2
votes
1answer
31 views
Checking if a passphrase is able to decrypt symmetrically encrypted files
I have about twenty files symmetrically encrypted with CAST5. I have a single passphrase that is meant to work with all of the files and I wish to confirm that it does. I wrote a script to perform a ...
-5
votes
0answers
36 views
shell script in unix [closed]
Write a shell script capable of doing the following:
create a directory "preFinal" in your home directory. In case that such directory exist, rename the existing one ino "preFinaal.000" and then ...
2
votes
1answer
36 views
What is happening when a script encounters an error in one of the commands?
I used alien to convert an RPM to a .deb. I did NOT use alien's script conversion; I'm converting by hand. Indeed, the script did barf on some non-compatible syntax. My question is NOT about how to ...
2
votes
1answer
81 views
bash script - supervisor program
I have to write a shell-script that have to do the following tasks:
-in every 5 seconds it saves:
-how many users are using joe and/or vi;
-if ...
4
votes
4answers
66 views
linux + how to ignore (filter) file with space
Sometimes a file name is created from a couple of names and space between each name as the following:
$ touch "A B C"
$ ls
A B C <-- one file but has three words ! ...
2
votes
1answer
52 views
Deleting a pattern from a file and appending it to the end?
I have a log file which have contents like below:
#SOME MORE DATA
These switches don't have latest images :
SWEs-elmPCI-A-01#
#SOME MORE DATA
These switches don't have latest images :
...
2
votes
3answers
78 views
Very strange behavior with grep and IFS
I'm having trouble using grep, the returned results are "n-empty", I mean without the 'n' character...
This is the script sample :
OLDIFS=$IFS
IFS="\\n"
i=$(grep -ril $1 *)
echo $i
IFS=$OLDIFS
...
1
vote
4answers
51 views
How can i run a piece of code in background?
Can I run a piece of code in background instead of using another script.
[sesiv@itseelm-lx4151 ~]$ cat ./testback2
#!/bin/bash
start_time=$(date +%s)
for i in {1..5}
do
./testscript &
done
wait
...
1
vote
2answers
40 views
How to find responsible script with ausearch results?
So I wanted to know which process is creating a directory ']' in my root. I was assuming this is some typo in some script. So I set up an audit for that directory, very similarly as shown on This ...
0
votes
2answers
56 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
6answers
109 views
extract a file from jar file and get the diff
In real world I have a xsd in a jar file across various releases I am trying to check whether xsd has changed across releases 10.x.y.z to 11.a.b.c
I have different release directories which are read ...
1
vote
2answers
83 views
Shell script execution
I have two shell script files with exactly the same permissions etc.
I can run one of them by just giving its name in the command line but for the other one I should use sh or ./ to run it.
What is ...
4
votes
2answers
51 views
Specifying a generic interpreter for a program like expect?
I am writing expect script which can be used on mulple operating systems but the problem is
i can't use #!/usr/bin/expect evreywhere so instead i tried to do
#!`which expect`
at the top but it ...
2
votes
1answer
29 views
exec cp failes from script, yet works when issued directly
I have a script that copies SQL backups to a windows server. Here's the line from /etc/fstab:
//my.win.box/share$ /winshare cifs ...


