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

learn more… | top users | synonyms (1)

3
votes
1answer
17 views

What's the difference between 'expansion' and 'substitution' in terms of shell programming's terminology?

Some documents such as Bash reference manual, Bash Hackers Wiki use the word 'expansion'. However, some other documents seem to prefer the word 'substitution'. (Advanced Bash-Scripting Guide). Is ...
10
votes
5answers
266 views

Stateful bash function

I’d like to implement a function in Bash which increases (and returns) a count with every call. Unfortunately this seems non-trivial since I’m invoking the function inside a subshell and it ...
4
votes
5answers
1k views

Print Matching line and nth line from the matched line

I am trying to print the matched line and the 4th line from the matched line (line containing the expression I am searching for). I have been using the following code: sed -n 's/^[ \t]*//; /img ...
2
votes
3answers
37 views

Increment look back value within a configuration file daily +1

I have a configuration file that needs to be incremented daily. E.g. report.lookback.days.to.retrieve.data=60 This file contains multiple entries such as the one above that contains different ...
0
votes
1answer
18 views

How to track SFTP's error

I have 1 script which is used for SFTP. I am getting error for permission issue on target server. I want to track this error in log file. How i can track the sftp's error. below is my code, sftp ...
3
votes
3answers
268 views

How to put the following information in a CSV file?

I have a text file with the following type of content: OPERATION_CONTEXT VMD1HTE1A71_ns:.oc.GJ_OAD2 alarm_object 1130 On director: VMD1HTE1A71_ns:.temip.VMD1HTE1A71_director AT Fri 18 Oct 2013 ...
3
votes
1answer
35 views

How to create multiple tar files with bash script and use date as file names?

I have a lot of files and want to create an archive for every 100 files i.e. the first 100 files are in one tar file, and the 101st to 200th files are in another tar file. And I want to use the date ...
4
votes
2answers
48 views

Script to loop through folders with numeric names

I am working on a bash script to compress the images in my Wordpress folders. The wordpress folder structure is as follows: > wp-content/uploads/2014/01/filename.jpg > ...
1
vote
3answers
85 views

How to write a Java Program / Shell Script combination such that you can call the Java program as a remote command and yet supply a local file?

This is related to How to execute a remote command on a local file? I wrote a simple Java program that prints the first line of a file - import java.io.BufferedReader; import ...
11
votes
3answers
289 views

Variable as command; eval vs bash -c

I was reading a bash script someone made and I noticed that the author doesn't use eval to evaluate a variable as a command The author used bash -c "$1" instead of eval "$1" I assume using eval ...
-2
votes
1answer
39 views

automatic capturing top output by cronjob CENTOS 6.5 x86_64

I have this command: top -n 14400 -a -b -d 1 > /toplogfile.txt I want to make a script which is run by cron every day to capture top output, and if it is possible gzip the output file after the ...
7
votes
5answers
308 views

How to extract logs between two time stamps

I want to extract all logs between two timestamps. Some lines may not have the timestamp, but I want those lines also. In short, I want every line that falls under two time stamps. My log structure ...
1
vote
1answer
415 views

Command/scripts to check the Reverse DNS Lookup time

I am working on a project in which one master communicates with numbers of slaves. For that it has to make connection with hosts in network. But sometimes it hangs. I think that the reason behind is ...
2
votes
1answer
30 views

Conditionals for fish shell

I am going through the fish shell tutorial and find that this simple if-else block does not work if grep fish /etc/shells echo Found fish else if grep bash /etc/shells echo ...
5
votes
2answers
197 views

Get the actions for a command programmatically

Let's take the git example: $ git<TAB><TAB> git git-import-dscs git-shell git-buildpackage git-import-orig git-upload-archive git-dch git-pbuilder ...
0
votes
1answer
44 views

How to assign variable in awk

I have a code like below: $ awk -F'[]]|[[]' \ '$0 ~ /^\[/ && $2 >= "2014-04-07 23:00" { p=1 } $0 ~ /^\[/ && $2 >= "2014-04-08 02:00:01" { p=0 } ...
2
votes
1answer
48 views

How to check input parameter for running shell script [closed]

I'm writing a shell script to be used for various purposes. Various operations depend on input parameters. How can I check which parameter has been passed to the shell script while it runs? Can ...
3
votes
1answer
420 views

Noninteractive script running over ssh is interrupted as apt-get finishes

When I run the following non interactive script on Ubuntu Server 13.04 it's interrupted when lxc-docker package finishes installation. Script : ssh -o StrictHostKeychecking=no -t -t -i $CERT ...
1
vote
1answer
428 views

Script that unpacks a initrd, allows editing of the preseed.cfg and the packs it to cpio and gzip again

I want to program a script that allows what is said in the title. So basically I gunzip the initrd, than unpack the cpio, open vi to allow editing, save, pack with cpio, and gzip again, so nothing ...
0
votes
1answer
193 views

Is expect tool availabe for ARM platform

I need to get expect (tool for automating interactive applications) for the ARM platform. Is it a readily cross compiled to ARM and is it available? I tried googling but was unable to get the ...
1
vote
1answer
27 views

Shell script fails to run on startup

I want an executable program to run on startup. For this reason, I created a shell script: /etc/init.d/server. Then I run chmod +x name_of_script and update-rc.d server defaults. server (script): ...
1
vote
0answers
16 views

Execute commands on TMUX Detach

Is it possible to execute commands on tmux detach? I usually have a rails console and server running in the tmux session, on detach is it possible to automatically end those? Thanks.
1
vote
1answer
470 views

Deleting Non-empty Directory with smbclient

How can I remove a non-empty directory with smbclient? I have tried the following: 1) rm Result: NT_STATUS_NO_SUCH_FILE listing [dir_path] 2) recurse;rm Result: No Error but also nothing ...
1
vote
2answers
54 views

shell script to find the combination of the array elements

I have a shell script in which I have defined an array. The array contains more than 2 elements. I need to find the combination of all the elements in my array. Suppose, if my array has the elements, ...
0
votes
1answer
223 views

“Expect” automation tool output to shell variable

#!/bin/bash # more commands here expect << EOD spawn telnet localhost 9151 expect -exact "Trying 127.0.0.1...\r Connected to localhost.\r Escape character is '^]'.\r" send -- "AUTHENTICATE ...
1
vote
2answers
54 views

copy files from one path to another path in linux

I am new to linux. I am trying to copy files from one path to another path. I have a text file which has all names of files in the following pattern: file-1.txt file-2.pdf file-3.ppt .... I created ...
1
vote
2answers
52 views

Editing a Java properties file with Bash

I have the following Java properties file that is maintained by humans. # file.input = /very/old/name # file.input = /old/name file.input = /current/name file.input.default = /default/name ...
1
vote
1answer
29 views

extracting specific substrings from string

I am trying to write a bash script. In a directory I have 2 fastq files: A-122-3.BH7WBVADXX.lane_1_P1_I24.hg19.sequence.fastq A-122-3.BH7WBVADXX.lane_1_P2_I24.hg19.sequence.fastq I just want to ...
26
votes
9answers
10k views

Correct locking in shell scripts?

Sometimes you have to make sure that only one instance of a shell script is running at the same time. For example a cron job which is executed via crond that does not provide locking on its own (e.g. ...
1
vote
5answers
2k views

Execute a command on multiple hosts, but only print command if it is successful?

Here's what I want to do. I want to check over 100 hosts and see if a file exists on that host. If the file does exist, then I want to print the hostname and the output of the command. In this ...
0
votes
7answers
3k views

Upload file to ftp server using commands in shell script? [closed]

I want to upload a file from my Linux server to some FTP server. I know we use put and get commands to upload and download files and the sftp command to connect to the FTP server. But I wanted to do ...
0
votes
0answers
22 views

How to find the currently running app from terminal on OS X?

I'm writing a shell script runs in the background and monitors user activity. I'd like to be able to capture current application/document if possible. Can I do that? (Cross-posting this from ...
8
votes
2answers
113 views

How do I elevate privileges in the middle of pipeline?

My guess was as follows: echo "Generating some text" | su - -c cat >/output/file But su says: su: must be run from a terminal What would you do?
2
votes
1answer
108 views

Bash command not found error

Why would the following script give following errors : ./check1.sh: line 10: Hi,: command not found ./check1.sh: line 21: syntax error: unexpected end of file check1.sh: #!/bin/bash subj="host ...
0
votes
2answers
33 views

command condition sometimes integer sometimes string

I want to execute this condition while [ $(cat /path_of a file/) -eq 1 ] The condition is only correct if $(cat /path_of a file/) is an integer and not a string ! How can I overcome this ...
1
vote
2answers
42 views

Bash: split list of files into different files?

I have several files in a directory like: data1.dat data2.dat .... data24678.dat To run another code, I need to have a text file with the names of the files but I need to split in 50 files per ...
4
votes
3answers
148 views

How do I read the output of commands in a script

I'm learning Linux scripting at the moment, and one thing I can get working is assigning a command output to a variable. The command service httpd configtest returns Syntax is OK, so I wrote this. ...
0
votes
1answer
51 views

Recursively delete hidden directory & its files?

I want to delete all hidden directoris from a directory and its sub-directory. I also use rm -rf .directory_name this command is iterative command I want to a recursive command. Please anybody help ...
0
votes
1answer
51 views

Can continually assigning a variable in a shell script cause a memory leak?

I've written a short script to copy Apache's server status to a log: #Save date and time to a variable dt=$(date) #Echo date and time to the log file as it's not included in server-status echo "Time ...
8
votes
3answers
1k views

What does $# mean in shell?

What does $# mean in shell? I have code such as if [ $# -eq 0 ] then I want to understand what $# means, but Google search is very bad for searching these kinds of things.
1
vote
0answers
56 views

how to list blocked connections events by the firewall?

So, I used firestarter that had logged blocked connections events with some useful details (but it is not being updated and I found somewhat unsafe as any moment we could click to deactivate the ...
1
vote
0answers
24 views

Running a script after tty1 has loaded

I have been attempting to write a script to run dcled on start up, the program that runs this. I am using Debian Jessie with multiarch enabled. This is essentially a small file server. I am ...
4
votes
2answers
197 views

How can I synchronize processes started in different TMUX panes?

Consider this: tmux split-window -d program1 program2 # this program depends on some side effects produced by program1 In this case, program2 will start before program1 is ready. program1 will send ...
1
vote
3answers
295 views

Line 4: $data: ambiguous redirect when using passwordbox

I want to create a passwordbox using the dialog package. #!/bin/bash data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 dialog --title "Password" \ --clear \ --passwordbox "Enter your ...
4
votes
2answers
73 views

How to kill a process started as daemon?

I start a process using foo &. It outputs something like: [1] 16915 This is the process id, I guess. How can I store this number into a variable named MY_PROCESS_ID (for example)? Then I ...
4
votes
3answers
500 views

Find files that have words in common

What would be the best way to create a list of files that have common words with a given file. For example, if I had: $ ls mainFile file1 file2 file file4 $ cat mainFile exquisite malicious ...
3
votes
3answers
98 views

Shell script too slow for output to Conky

I want the output of stdbuf -i0 -o0 -e0 jack_cpu_load | sed -n 's/[A-Za-z]*//g;s/ //g;s/.\{4\}$//;9,$p' to be displayed in Conky but, I suspect, Conky is starting the script with every refresh and ...
1
vote
1answer
24 views

mailx and HP-UX to RedHat migration

We are migrating some servers from HP-UX to Linux RedHat, and we have to migrate about 100 shell scripts that are referencing /usr/bin/mailx (instead of /bin/mailx on Linux). We'd like to change all ...
3
votes
1answer
28 views

How can I tell whether a package is installed via yum in a bash script?

I am trying to write a script that installs packages, but if it fails at any point later in the script rolls back whatever it installed. Of course if the user has already previously installed a ...
0
votes
2answers
86 views

Scripting Language Evolution [closed]

I have an assignment due Monday and I need some help because I have no knowledge on the subject and can't even understand what to search exactly. I am not waiting for an essay or something just some ...