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

learn more… | top users | synonyms (2)

0
votes
2answers
388 views

EOF blocks my script?

I have this script (it is actually a snippet from a bigger script). #!/bin/sh if [ $actualsize -ge $MAXSIZE ]; then read dummy FILEPOINT <<EOF `dd if=myfile skip=8001 count=1 bs=1|od -x` ...
1
vote
2answers
1k views

Need to get the latest file with date timestamp for each month

I am just starting with Unix programming and I have a requirement. I have four files which are placed in my landing zone and I need the scheduler to pick up the latest file of that month and year. ...
0
votes
1answer
200 views

set command with — flag

I have a file (called text) that contains two fields of strings (separated by space) like what follows: 1.2.3 version1 When I use set command as follows, I have the first field in the $1 and the ...
3
votes
1answer
469 views

ls gives me different sort orders during a cron job

I have a cron job that, among other things, does a recursive ls of a directory into a file. This gets compared to another file that I've created that, supposedly, contains an identical listing of the ...
5
votes
3answers
6k views

Editing config file via a bash script

I've been trying to write a simple bash script which I'll be using to install an application and update it's config file. I'm having hard time to have get it's config file modified. # ...
2
votes
1answer
908 views

How to check if a currently running process is opened by root or user

I'm currently creating a BASH script to kill off processes. I first check if the process is running then kill it. But I would like to add a nested if to find out if that process was opened by root ...
4
votes
1answer
436 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
475 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
237 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
1k 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 ...
20
votes
3answers
61k 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
964 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
3k 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
480 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
121 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 ...
13
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
756 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?
12
votes
3answers
3k 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
264 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
6k 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 ...
4
votes
4answers
7k 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
481 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
597 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
4k 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
273 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
499 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
208 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
136 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
4k 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
5k 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
422 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
629 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
930 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
192 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
255 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
599 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
216 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
270 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
429 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 ...
7
votes
2answers
21k 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
112 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
407 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
458 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
104 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 : ...