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

learn more… | top users | synonyms (2)

1
vote
2answers
246 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
292 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
3answers
478 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 ...
11
votes
2answers
30k 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
128 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
58 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
459 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
533 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
106 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
864 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
601 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
161 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
400 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
86 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
880 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
118 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
125 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
2k 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
590 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
847 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
253 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
582 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
2k 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
213 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
157 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 ...
7
votes
2answers
25k 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
389 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
5k 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> ...
12
votes
10answers
40k 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
3k 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
247 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
1k 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
303 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
527 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
5answers
28k 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
332 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
525 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
352 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
253 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
220 views

can something besides the shebang set the interpreter? [closed]

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
748 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 ...
1
vote
2answers
697 views

How to check in a shell script if an executable is running or not?

I have put an executable in a shell script file abc.sh. Now, I want to add one line in this abc.sh, to know whether it is running before my script starts or not and if yes, the kill that executable.
5
votes
2answers
6k views

What's the diference between comparison inside if using two or a single equal (=)

Read that for comparing string inside if we need to use double square brackets. Some books says that comparison can be done by =. But it works withe == also. #!/bin/bash a="hello" b="world" if [[ $a ...
2
votes
2answers
124 views

What makes the shell interpret these redirects as follows?

Can anyone help me understand this seemingly odd behavior of how the shell parses the redirects..? $ cat > test.txt Line 1 Line 2 $ ls -i dummy.txt dummy2.txt ls: dummy.txt: No such file or ...
0
votes
1answer
312 views

perform ping test to change dns

I wrote this script to check if my dns server works fine or not, and if not change it. but it gives out error ./dns-ping.sh: line 15: ((: 3 < : syntax error: operand expected (error token is "< ...
2
votes
2answers
408 views

add “#” in begining to selected lines in File

Requirement : ADD someting (i.e #) in begining of every line in file A which is grep from file B File A abcd abdc sdfg asdfa jon ram File B jon abcd grep file B from file A and add "#" ...
2
votes
1answer
872 views

How to create a password protected shell script [duplicate]

How can I create a password-protected shell script for read/write access. It should also be executable by all users without the password. I have sensitive information in the script.
0
votes
2answers
348 views

read file record by record and do transformation to the subsequent record based on above record and write into another file

Data file is fixed length file, and I want to read the file record by record and do transformations to the subsequent records based on the prior records (and write the results into another file). ...
1
vote
1answer
408 views

stop processing in shell script but don't exit

I've got a script that I run continually to monitor vsftpd logs. Here is a small example: #!/bin/sh tail -n0 -F /var/log/vsftpd.log | while read line; do if echo "$line" | grep -q 'OK UPLOAD:'; ...