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

learn more… | top users | synonyms (2)

2
votes
1answer
19 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 ...
3
votes
1answer
21 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
47 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
66 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
20 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
27 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
24 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
56 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
14 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
22 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
25 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
23 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
35 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
37 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 [ ! ...
-2
votes
0answers
20 views

using mysqlimport on a large amount of csv files in a directory via bash scripting [on hold]

I have a directory with approximately 75 csv files in it that I need to mysqlimport into a MySQL database. The MySQL database does not have the tables created. The files: * The data is all numbers ...
1
vote
1answer
24 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
37 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
37 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
57 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
94 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
39 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
137 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
52 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
31 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
15 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
367 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 ...
1
vote
2answers
51 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
83 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
13 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
26 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 ...
4
votes
1answer
111 views

Proper way to distribute shell scripts

What is the most proper way to distribute shell scripts, if behaviours of shells can be modified by set and thus are unpredictable? For example, rm *.txt wouldn't be executed as expected on the ...
-1
votes
0answers
48 views

Unique id for combination of Latitude - Longitude

I have a LibreOffice Calc table containing one column with latitude and one with longitude. What I want to do is for every unique combination of latitude and longitude a unique number to be assigned ...
2
votes
1answer
37 views

Arrow key/Enter menu

I need help finding out how to possibly create a menu in a shell script that will display 3 options that a user will use the arrows keys to move the highlight cursor and press enter to select one. If ...
1
vote
1answer
25 views

bash script not being run by cron [duplicate]

I have a very simple bash script that runs flawlessly when I do ./removeOldBackup.sh or sh /home/myusername/backup/removeOldBackup.sh but when I add it to crontab like * * * * * sh ...
1
vote
0answers
23 views

Trap not trapping SIGTSTP

I have a script that keeps displaying the login prompt: #!/bin/bash trap '' 2 20 while true; do login done This is part of a bigger project so please don't tell me to just use the system login ...
4
votes
2answers
35 views

How to sort a collection of lines from different files?

I want to sort second line in each file by second column, and also print name of the corresponding file. I am doing it like this - rm tmp; for filename in file*; do num=`head -2 $filename | tail ...
2
votes
2answers
77 views

How to clear the input in Bash

I have a bash script that is reading quite a bit of data /dev/random. I need the user to type randomly to seed the random daemon. However once the script completes everything typed will get dumped to ...
1
vote
1answer
48 views

Memory buffer in a bash script

I have recently finished a script that will ask for a hostname and automatically take the argument of the function and ssh into one of my work servers. Here is a copy of my script: #!/bin/bash echo ...
6
votes
7answers
203 views

Count total number of lines before/after a pattern match

I am having a long list of IP addresses, which are not in sequence. I need to find how many IP addresses are there before/after a particular IP address. How can I achieve this?
2
votes
0answers
29 views

Shell scripts for the database logs

The actual log file will be like this $ cat file1.log time=2014-07-23 23:56:28 GMT, user=[unknown], db=[unknown], host= pid=28254 LOG: time=2014-07-23 23:56:28 GMT, user=portalman, db=ss, ...
3
votes
3answers
51 views

How to read a text file line by line which is not constant in shell scripting

I need to read a text file line by line and the lines are not constant it may vary.For example $ cat file1.txt syntax error at or near "?" at character 1 syntax error at or near "[" at character 1 ...
8
votes
3answers
384 views

Creating a Bash script that will execute a program and if it exits without crashing, will run it again

I'd like to know the easiest way of creating a bash script that will run an app in MacOSX (it's a UNIX based system so I assumed this was the right place). wait for the program to exit. If the exit ...
6
votes
2answers
159 views

Is there a way to convert a zip to a tar without extracting it to the filesystem?

Is there a way to convert a zip archive to a tar archive without extracting to a temporary directory first? (and without writing my own implementation of tar or unzip)
4
votes
6answers
56 views

reading a list of lines from a file writing output to a utility

I have a file with a list of lines I want to read from another file. I want to output those lines to a utility (grep) that lets me read the entire line and pull information from it. The file with the ...
-2
votes
0answers
14 views

How to apply label in clearcase through unix [closed]

I'm new to scripting. I came across this, I have to create a label for file while checking out I tried command mklabel but it did not work for me. I think I'm not using it in the right format. I work ...
3
votes
2answers
39 views

fdupes - delete files after comparing two directories

I'm currently trying to solve an issue using fdupes. I'd like to compare two folders with each other, and afterwards delete all duplicate files within one of these directories. Example: Files are ...
2
votes
1answer
47 views

How to set parameter zero ($0) while executing a script?

I can manipulate positional parameters using shift or set -- while a script is interpreted. How can I change $0?
1
vote
2answers
170 views

How to iterate through multiple file extension without caring about case sensitivity?

I've seen various topics on how to iterate through multiple file extensions but in most case, the list is defined. example: for file in ${arg}/**/*.{txt,h,py} do .... done As can be seen, ...
5
votes
3answers
184 views

How to iterate through a list of files with spaces that is sorted (case insensitive)?

I am doing this in OSX which uses bash but obviously, not all bash conventions are used so hopefully your suggestion is available to me :) I have the following files fun bar1.txt Foo bar2.tXT ...