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

learn more… | top users | synonyms (2)

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
368 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
548 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
67 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
814 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
182 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
242 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
550 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
196 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
245 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
366 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 ...
3
votes
2answers
15k 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
103 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
56 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
350 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
423 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
102 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
666 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
529 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
137 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
291 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
81 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
601 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
110 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
2k 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
105 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 ...
0
votes
0answers
1k views

IBM V7000 scripts for monitoring

Hello (I'm no hard core coder:), I try to develop a script to do some very basic monitoring on an IBM SVC. My goal is to get some information about the nodes and my quroum status and then send ...
4
votes
5answers
413 views

How to use ' in alias?

I have one-line that I want to call using alias. while printf '%s ' "$(df -P / | awk 'NR==2 { print $(NF-1) }')"; do sleep 30; done I tried to escape ' like \' but it didn't work. What is the ...
0
votes
5answers
559 views

How to display result of df every 30s? [duplicate]

All I want to see is the % after I issue df / every 30s but on the same line just after the previous number. So the final output would be 86% 86% 86% 87% 87% ...... Could it be one line code? Or ...
5
votes
2answers
198 views

Modifying zsh globbing patterns to use with cp

I'm trying to write a script to copy files recursively from a particular folder except files A.extn, B/*.extn and C/* where B and C are directories and extn is just some generic extension. This is ...
0
votes
1answer
496 views

Starting Resque worker with script doesnt work, starting by hand does

I am trying to figure out why my process doesn't work if started via a script, but works fine if started by hand. Here's the details: script is a resque worker start script. The script location is ...
3
votes
3answers
1k views

How to convert all .wav files in subdirectories to .aac using neroAacEnc?

I have a collection of music in .wav format, and would like to convert it to .aac/.mp4 using neroAacEnc. How do I do this? I am using Arch Linux x86_64 and Xterm.
8
votes
0answers
209 views

how to get exit status from the command before the last [duplicate]

I have solaris machine ( solaris 10 ) please Look on the following simple commands (haconf -makerw | grep -iq "Cluster already writable") # haconf -makerw VCS WARNING V-16-1-10364 Cluster ...
0
votes
4answers
137 views

concatenating multiple files with multiple headers

Im trying to concatenate multiple files with multiple headers to have one file with all the information in it for example. File 1: Numbers 1 2 3 Letters A B C File 2: Numbers 4 5 6 Letters D E ...
4
votes
2answers
18k views

How can I run a shell script as a daemon under Redhat?

I've got a shell script, which is essentially a one liner with some logging, which I'm trying to run this from an init script. I'm using the daemon function inside of /etc/init.d/functions to run it, ...
1
vote
1answer
347 views

Guide/help using Dialog with bash scripting

While I understand how to create menus, no guide I've found teaches how to actually link them to commands I was hoping to have something like: dialog--clear --title "n00b's spellbook" \ ...
1
vote
1answer
4k views

XML parsing using xmllint and customizing the output

I have xml file (say input.xml) of the following schema: <?xml version="1.0"?> <TagA> <TagB> <File Folder="FOLDER1M\1" File="R1.txt" /> </TagB> ...
7
votes
7answers
19k views

Show sum of file sizes in directory listing

The Windows dir directory listing command has a line at the end showing the total amount of space taken up by the files listed. For example, dir *.exe shows all the .exe files in the current ...
1
vote
0answers
2k views

Using sshpass, return code (exit status) differs for reasons unknown using valid commands

There are a few things going on here but I think ultimately, either CLish or SSH is returning an exit code that is messing up my work flow. I'm attempting to connect to a remote machine (CLish shell) ...
2
votes
2answers
220 views

What scripting language can I use to automate a concatenation & zipping process?

For a project I'm doing I need to concatenate and compress (with zip) many (midi) files and compare their sizes. I've thought there must be some language that allows me to do something like this: ...
2
votes
2answers
791 views

How do i know the process ID of the parent process?

I have a script with loop like while read host do ./script & done I want to know the process id of the current process which is starting the ./script in background and use it in script.
0
votes
1answer
270 views

How to get the arguments to a php function via grep?

I am writing a script to let me know the database login info for each PHP-based web site on a server that I am migrating. The login information is usually done either like this: ...
1
vote
1answer
433 views

chmod and chown not working in sudo called script

Based on this Serverfault question, my git user has permission in sudoers to run a wrapper script to move files into my webroot with git. Everything is working fine except for the chmod and chown ...
14
votes
6answers
15k views

Check if folder is a mounted remote filesystem

What is the best way (reliable, portable, etc.) to check if a given folder is on a mounted remote (nfs) filesystem within a shell script? I am looking for a command that would look like: ...
1
vote
1answer
239 views

how to use syslog to avoid log file being garbled when multiple proceses are trying to write to the same log fille?

I wanted to know usage of syslog when multple processes are trying to write to the same log file like for i in $var do some process >> logfile & done wait
4
votes
1answer
402 views

Prompt for confirmation for every command

I'm writing a pretty ad-hoc install script for some thing. No much control constructs, basically just a list of commands. I'd like the user to confirm each command before it gets executed. Is there a ...
1
vote
1answer
279 views

What does mean ` AWK=@AWK@` in shell scripting

I found AWK=@AWK@ while reading sh script, it's something like AWK=$(which awk), but it's not working. So can anyone explain this ? Script : #!/bin/sh - # makelist.sh: Automatically generate header ...
1
vote
2answers
215 views

bash if statement behaviour question

I wrote this following piece of bash script. if [ $(tmux has -t junk) ] then echo zero else echo one fi It always returns one, no matter if the session exists or not. I checked in the command line ...
0
votes
2answers
190 views

can something besides the shebang set the interpreter?

I'm running a script (in tmuxinator) that tries to source another script (rvm). rvm explicitly does not allow sourcing from sh. I didn't think that would be a problem, because the shebang in the ...
0
votes
1answer
594 views

Why doesn't this variable assignment work when using tee?

Consider: $ FILE_NAME=`(cat somefile | head -1)` | tee -a dump.txt $ echo $FILE_NAME $ Now, why doesn't the output of (cat somefile | head -1) reach the standard input of tee ..? If the output ...