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

learn more… | top users | synonyms (2)

0
votes
0answers
16 views

I have to calculate values from two files and store the result in output file [duplicate]

I have to calculate values from two files and store the result in output file: in output file each record shows the product of records with same name in input files. file one s1 10 s2 20, s3 25, s4 ...
-3
votes
1answer
81 views

I have to calculate values from two files and store the result in another file — using shell

I have to calculate values from two files and store the result in output file. In the output file, each record shows the product of records with the same name in input files. file one s1 10 s2 20 ...
1
vote
2answers
42 views

Sending most recently created file via Email

I'm trying to send a log file every 24 hours or so via email. Currently I am using mutt for this. You can call mutt like this: mutt -s "Log" -a file_attachment example@example.com I know I can ...
0
votes
1answer
57 views

Copy a file from a remote server to windows home using scp

Is there a way to copy a file from a server to a local folder (i.e. My Documents)? can it be done by scp? I have this script that generate some list. I want this script to automatically copy the ...
2
votes
1answer
48 views

Exit status on core dump

When a process dumps core, does it set any particular exit code? Alternatively, is there a way to detect if core was dumped in a shell script. I have shell script that fires a job which occasionally ...
1
vote
1answer
39 views

Compare file size of multiple files in an array [closed]

Scenario: Ftp site has 100s of files. Once a day, all the .gz files are copied to an AWS site then renamed. Only the date is kept in the file name. Some of the files corrupted during copy. A txt ...
2
votes
2answers
247 views

condition && command + exit

While writing a simple shell tool, I found a piece where I don't know how to get it to work. [ "$#" -ne 3 ] || echo "wrong number of arguments" && exit The above works as intended because ...
2
votes
2answers
52 views

How to escape spaces etc in passed variable, for system call to cp in awk

As the title suggests, this problem has enough layers of complexity to make simple escaping characters difficult for me. I have a bash script which, for a large part, has an embedded awk script that ...
2
votes
0answers
26 views

Tmux log output [duplicate]

Im looking for a solution to an issue regarding tmux. One of my scripts ns2server stopped working recently when running start (using tmux) but not in debug mode (not using tmux). I found that using ...
6
votes
4answers
353 views

Delete spaces, hyphens, and underscores in filenames?

What is a good command to delete spaces, hyphens, and underscores from all files in a directory, or selected files? I use the following command with Thunar Custom Actions to slugify filenames: for ...
2
votes
2answers
79 views

Replace value within single quotes in a line that contains certain word using sed command

I have a line as below in a html file, shahar.push(['remoteUrl', 'staging.zazzercode.com']); Depending upon environment, I want to replace the remoteUrl value with sed command. eg, ...
2
votes
3answers
147 views

Script for testing SFTP login status?

I need to perform an automated backup task that connects to an SFTP server. The first stage involves testing the server connection by connecting to it. To be absolutely sure that it is connecting to ...
1
vote
2answers
66 views

How to add words to an existing column

I have a tab delimited file with 10 columns and in one of the columns (with about 40 million rows), I would like to add a word before the existing entry in each row (same word in each row!) and a ; ...
6
votes
3answers
156 views

Attempted assignment to non-variable?

We can use arithmetic operations inside shell script function: function mess { if (( "$1" > 0 )) ; then total=$1 else total=100 fi tail -$total /var/adm/messages | more } I ...
1
vote
2answers
92 views

Pass a command to ROOT from a shell script and having it stay open

I am writing a bash script to perform some analysis using the program ROOT. I want to run some initial command to load the result of the analysis, then continue using ROOT interactively. The analysis ...
0
votes
1answer
74 views

Launching a program and executing a command in bash script [closed]

How can I execute a command inside ROOT that I launch within the bash script? My aim is to have ROOT execute its GUI file browser and have it open if the user does not interfere with keyboard ...
0
votes
1answer
48 views

Combining multiple functions into a single bash script

Is there a way that I can combine the following commands (the last is a zsh function) into a single bash script? find /path/to/directory/*/* ! -name "*.js" -type f -delete find ...
4
votes
4answers
63 views

Renaming multiple files with rename

I need help renaming files in batch--the other questions I browsed don't exactly address my problem. The names of my files are generated non-deterministically, so I can't predict what they will be ...
0
votes
0answers
23 views

How to capture INFORMIX DB errors in shell script?

I need to capture the informix DB errors like Update failed, Insert failed using the shell script. I am using ksh shell.
5
votes
1answer
157 views

Multi-Threading/Forking in a bash script

I have written a bash script which is in following format: #!/bin/bash start=$(date +%s) inFile="input.txt" outFile="output.csv" rm -f $inFile $outFile while read line do -- Block of Commands ...
5
votes
3answers
58 views

How to put the output of the trailing lines of grep in on-line?

Assuming that I have this file: Thu May 8 15:32:07 2014 User-Name = "Mark" Framed-IP-Address = 0.0.0.0 Acct-Status-Type = Interim-Update Acct-Input-Octets = 95684 ...
3
votes
1answer
43 views

How do I parse a string in bash into variables using a tab as the delimiter and preserve spaces?

I am in the process of writing a bash script to display various statistics, some of which come from a MySQL database. The pertinant code I'm having difficulty with is: read min max rows <<< ...
0
votes
1answer
74 views

Command not working in shell script, but works on command line

I have a shell script that executes the following command: bash -c "screen -dmS node /home/nodejs/bridge/bridge.js" However, the screen is not being started. Typing the command... screen -dmS node ...
3
votes
2answers
122 views

Unable to pass a bash variable as a python argument in bash

For some reason I cannot pass the bash variable $FOLDER as a python argument on the following code. The python script downloads some files from amazon s3. Bash script: #!/bin/bash FOLDER=$(./aws get ...
0
votes
1answer
44 views

Mandatory argument for script to run java program

My script is called: report_startDate It has the following line: $JRE_ROOT/bin/java -cp /home/me/report/config/:/home/me/report/jar/reporting-1.0-SNAPSHOT.jar com.me.project.report.Main $1 $1 ...
3
votes
1answer
49 views

grep upto matching brackets

I have a file like this:- pin(ABC) { a b c d e f { abc } } pin(XYZ) { g h i j k { j k { ...
2
votes
0answers
33 views

background gui process in shell script

In the below script, ivfstudio commands open a gui. Even launched as a background process, I need to close it first so that the next commands are executed. How to make it "really background" ? ...
3
votes
1answer
95 views

two if conditions in for loop bash scripting

I've trying to make two if conditions in for loop. Is it possible this? Now doesn't return anything from second if only two OK from first if. #!/bin/bash servers=("212.39.82.157" "212.39.82.157" ...
1
vote
2answers
29 views

rename a batch of files after reading from a source file

I have a directory full of over a thousand files and the names are bit long (and no pattern found in the naming style). I would like to simplify the filenames. E.g.: ...
2
votes
2answers
41 views

Read Multiple Entries from an Input File

I wrote a program in Fortran that asks me for latitude and longitude and the name of the output file every time I run it. It works great. What I have been meaning to do is run this program for the ...
0
votes
1answer
29 views

What is the term “Usage”?

I am seeing this a lot in the scripts. Is "usage" a command in unix ? I tried googling it but got ambiguous results. Here is an example : ${1?"Usage: $0 ARGUMENT"}
0
votes
1answer
40 views

Connect psftp between Unix and Windows server

I need to transfer files from Unix to Windows server. After creating a folder in the windows server files need to be copied from Unix to Windows. I am using psftp to do this process.So, I am trying to ...
0
votes
1answer
45 views

How to evaluate a variable length in shell script?

I want to write a shell script, in which it will call different command according to the variable length. But I didn't figure it out yet. My unwork script is here: for i in n5 n25 if ${#i} == 2; ...
-2
votes
1answer
46 views

Installation script for OpenERP, creating directories under /var

I would like to know what this code means. I found it on the OpenERP forum. It is supposed to run on Linux CentOS. adduser openerp DIR="/var/run/openerp /var/log/openerp" for NAME in $DIR do if [ ! ...
1
vote
1answer
42 views

How can I use global variable arrays in aliases or functions

I am attempting to simplify repetitive work procedures. In doing so, I am trying to write a .bashrc script which will set global path variables that aliases can refer to. Disclaimer: I'm new to linux ...
1
vote
0answers
63 views

How to properly start and stop shell script in linux, busybox?

I am trying to write a small shell script that would send some commands to my tv set from my set top box that has busybox on it. The problem is that it generates huge amount of zombie processes, and ...
0
votes
2answers
59 views

How to kill a process in shell script which is running through cron?

I have a shell script which runs in cronjob. This shell script has to kill a process which is running and start the new process again. When I run the script manually it works perfectly fine, but when ...
-4
votes
3answers
78 views

Birthday reminder

write a bash shell script to get the alerts of friend's birthday Suppose Birthday Date Friend's name 08-02-2014 : Prashant 08-15-2014 : prabhat 09 -16 -2014 ...
2
votes
4answers
106 views

Change to the last modified subdirectory of the current directory

I have an application which generates a couple of files in different directories at a regular interval and I need to check the latest files generated, i.e. the file which is generated in the most ...
0
votes
1answer
64 views

Writing a Bash script to run and end at specific times

I'd like to create a script that will do the following. Start at a given time during the day and end at another given time. So for example, I have a program I'd like to test, so my script would be ...
-1
votes
1answer
19 views

A command showing if I have the right to perform writing?

I'm searching for a command which only says if the current user has r-rights (read) on the file passed as a parameter. This command could be something like haveIRights -x <file> and it has to ...
8
votes
1answer
158 views

How to append multiple lines to a file with bash, with “--” in front of string

Question very similar to How to append multiple lines to a file with bash but I want to start the file with --, and also append to the file, if possible. printf ...
2
votes
3answers
70 views

moving a (file | directory) while avoiding filename collisions

I have a bash script that moves files from a number of different locations to a folder named completed. I want to avoid overwriting previous files, so in the case when the name of a file (for ...
2
votes
3answers
62 views

waiting for network in a bash script

I'm running a script that relies on network being up and a network share be mounted. The script runs on login (which happens automatically after boot). The problem is that by the time the script runs, ...
3
votes
0answers
18 views

Get notified from avahi

After looking for a zero-conf browser valid implementation I realised that inside my linux machine (ubuntu) I already have avahi and typing: avahi-browse -alr I get a complete list of all devices ...
8
votes
6answers
475 views

How can I test if a variable is empty or contains only spaces?

The following bash syntax verifies if param isn't empty: [[ ! -z $param ]] For example: param="" [[ ! -z $param ]] && echo "I am not zero" No output and its fine. But when param ...
0
votes
2answers
113 views

Unix Shell Scripting output to an Excel File

I have a Shell script with Multiple SQL statements like this: select Count(*) from Emp where date= current_date-1; After executing the Shell script i need a MS excel file to be create with Column ...
2
votes
3answers
106 views

Count files in a directory by extension

For the purpose of testing, I'd like count how many images files are inside a directory, separating each image file type by file extension (jpg="yes". This because later it will be useful for another ...
1
vote
1answer
30 views

Make some fields required in dialog

The script below creates a dialog box. The user can press Enter at any time, and then the script continues. I need to block the Enter key to ensure that the user fills all the fields. How can I do ...
2
votes
0answers
105 views

Running shell script inside with vagrant provision

I have setup a vagrant box using precise64 (ubuntu 14.04) and installed packages needed for octopress. I can ssh into the vagrant box and generate posts and run preview for my octopress site. Now I ...