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

learn more… | top users | synonyms (2)

2
votes
2answers
557 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
156 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
342 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
85 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
760 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
116 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
116 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
511 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
739 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
233 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
551 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
211 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
147 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 ...
6
votes
2answers
22k 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
370 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> ...
10
votes
9answers
32k 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
236 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
290 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
487 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
23k 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
291 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
488 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
324 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
241 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
211 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
678 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
668 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
5k 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
120 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
297 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
386 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 "#" ...
1
vote
1answer
789 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
319 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
376 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:'; ...
2
votes
1answer
451 views

Open any kind of application with BASH

I have made a Java program that could open any application. Suppose there is a file name "*.jpg", the it would allow the OS to recognize the type of application and then open the default application. ...
2
votes
1answer
2k views

Run expect script from other shell

My target is to create the /var/tmp/add_user.bash script from /var/tmp/create_script_add_user.bash script and run the expect script (add_user.bash) from create_script_add_user.bash script. The ...
0
votes
2answers
502 views

How to make any file and put contents in that using script

I want to modify configure.sh to create a file /etc/pam.d/XXX with some predefined content. How can I do this by putting the file's absolute path and content in configure.sh? Please explain the ...
2
votes
1answer
244 views

Bash: pair up two series of files

I have a number of files with this pattern: file1_foo.ext file1_bar.ext file2_foo.ext file2_bar.ext and so on. I need to "pair them" and put them in a file like this file1_foo.txt ...
13
votes
4answers
14k views

Why doesn't “sudo su” in a shell script run the rest of the script as root?

A sample script can be as below: #!/bin/bash sudo su ls /root When using ./test.sh as the normal user, instead run ls as super user and exit, it switches to root; and when I logout, it executes ls ...
2
votes
3answers
6k views

Compare multiple files

I want a bash-script to compare OR find differences for multiple files which are stored in different locations: Files under /tmp/test/ A.txt B.txt C.txt Compare with files under /home/oldtest/ ...
0
votes
1answer
105 views

Colon breaks the variable subsitution [closed]

I am trying to lookup some C functions so that I could debug while using strace. So I setup a bash function to look it up in firefox (or links), but the substitution falls apart with : and escaping ...
2
votes
1answer
200 views

How do I move .bash_profile away from home

I need .bash_profile to be synched with Dropbox. The easiest way I can think of is to "redirect" the shell to search for .bash_profile in a custom folder. So is that possible? Or are there any better ...
1
vote
1answer
359 views

How to explicitly load shell interpreter in a C program

I want to create an executable script which is not readable/writable However since an interpreter needs to read this file it is not possible to do so directly. Therefore I wanted to know if I could ...
1
vote
2answers
300 views

Merge chunks from multiple files

I need to merge chunks from a few but large files. Each line contains the file name and byte offsets. # file begin end foo/a 11970 12010 foo/a 22995 23035 foo/b 45090 45130 foo/b ...