Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

4
votes
1answer
374 views

output while reading keyboard input

I'm trying to write a script that will ssh into a box, start a processes that needs to be monitored (by a human) for success or failure then move onto the next box and repeat. I've been trying to use ...
0
votes
3answers
401 views

using find, exec, sed to manipulate strings as args to another program

I can use find like this find -type f -path "./src*" -name "*.php" to find a list of files. For example ./src/Superuseradmin/Model/Mapper/UUID.php What I need to do is manipulate each string in the ...
4
votes
3answers
3k views

How to remove any string from a file via shell scripts?

I try to remove string from .bash_profile. String is added when my shell script run: My string at bash_profile as follows: # for Myapllication export MYAPP_HOME=/opt/myapp I want to remove the ...
0
votes
1answer
210 views

Unexpected whitespace using sqsh in command substitution [closed]

Below shell script instruction behave in weird way ARG_DATE=`sqsh -S $SERVER -U $DB_USER -P $DB_PASSWORD -D dbname -h<<END SET NOCOUNT ON go select convert(varchar, PRIOR_COB_DATE, 112) from ...
0
votes
4answers
914 views

echo a loop with variables command

I have several lists and want to run some commands over them. As lists are long I want to run those commands parallel to each other, hence using nohup. For every item I tried to echo a loop that ...
14
votes
3answers
43k views

How to append multiple lines to a file with bash

I am writing a bash script to look for a file if it doesn't exist then create it and append this to it: Host localhost ForwardAgent yes So "line then new line 'tab' then text" I think its a ...
2
votes
2answers
816 views

How to compile a selection of Markdown documents using a shell script

Technical authors are increasingly being encouraged to write in standalone topics. Topics are written so that they make sense when compiled into different packages or when they are read in ...
1
vote
1answer
2k views

Comparing file times in ksh

I have developed a script which will compare two dates. #!/bin/ksh #################################################################### # #DECLARING ALL THE VALUES AND PATHS # ...
1
vote
0answers
479 views

Log in to multiple remote servers and execute a script [duplicate]

I want to make a script that will remote login to the multiple servers listed in a txt file like 10.3.9.6 10.3.9.7 and all servers have same username and password. and want to capture the output of ...
5
votes
1answer
120 views

What do you 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 ...
12
votes
6answers
2k 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
3answers
725 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?
11
votes
3answers
2k views

Can't indent heredoc to match nesting's indent

If there's a "First World Problems" for scripting, this would be it. I have the following code in a script I'm updating: if [ $diffLines -eq 1 ]; then dateLastChanged=$(stat --format '%y' ...
1
vote
1answer
243 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
2k 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
1k 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 ...
4
votes
2answers
5k 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 ...
3
votes
4answers
6k 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
450 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" ...
5
votes
4answers
551 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 ...
5
votes
2answers
3k views

Writing starting from a certain line number in a text file

In a bash script I want to write some lines to a text file, but this file has already been used before and there are texts in it. So I want to echo some additional text in it, starting from a certain ...
0
votes
2answers
53 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 ...
7
votes
1answer
260 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 ...
0
votes
2answers
449 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
200 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 ...
0
votes
1answer
128 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 ...
15
votes
1answer
3k 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 ...
6
votes
4answers
4k 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
383 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
4answers
573 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 ...
-3
votes
1answer
68 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
856 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
186 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
250 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: ...
2
votes
2answers
570 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
202 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
252 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 ...
3
votes
2answers
377 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
2answers
17k 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
105 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 ...
2
votes
1answer
57 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
372 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
436 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
103 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
696 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 ...
2
votes
2answers
533 views

Ubuntu Bash - Changing permissions to user files for automating Apache VirtualHost creation

Moved here from AskUbuntu I currently have a small Ubuntu Server 12.04 machine (test environment) with about 3 non-root users created. Each user has their own public_html directory under their ...
1
vote
4answers
149 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
302 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
82 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
644 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 ...