0
votes
1answer
41 views

Running shell script on cluster in parralel

I thought dsh(Distributed Shel) will be a good option but when i ran my shell script across my nodes, I didnt get expected output, dsh -aM -c bash /home/cloudera/bash_script.sh server2@x.x.x.110: ...
2
votes
1answer
19 views

ionCube shell script gives error

I have this shell script to install ionCube loader: if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi echo "Welcome to this script to install the ionCube loader on CentOS!" cd ...
2
votes
1answer
18 views

Comparison of columns in two files and appending the first file

I need a help on this :- I have a file : emp.txt 21356 suresh 12/12/2012 23511 ramesh 11/06/2011 31456 biswajit 09/08/2013 53134 archan 06/02/2009 first field:- employee id, 2nd field is name and ...
3
votes
1answer
165 views

How does the colon sign and dollar question mark combine in sh?

The "colon sign" and the "dollar question mark" can be combined to check if a sh script does have an argument and assigns it directly to a variable of interest: cmd=${1:? "Usage: $0 ...
3
votes
1answer
24 views

X commands do not start from my at job

I'm learning about Linux scheduling commands including at, cron, sleep etc. I'm trying to launch gedit after x minutes via the at command. This is what I have: kedar@i5 ~ $ at now + 1 minute at now + ...
1
vote
1answer
31 views

How to assign words with spaces as a whole name to variable in shell script? [duplicate]

I need to make some directory of Author name. It's easy when doing them alone. I can simply mkdir "Mario Luis Garcia" This will create one directory named "Mario Luis Garcia" But when trying do it ...
0
votes
2answers
47 views

Getting expr: syntax error on index [duplicate]

Using this OF=$(ps fax | grep 'php-fpm: master process' | awk '{print $1}') IDX=`expr index $OF ' '` I get an error. The results of the $OF variable are: 27797 27495 What is the error here? I ...
1
vote
3answers
78 views

How to get a response from any URL?

I have been asked to write a shell script To check if a URL is UP/Working or not for my Project. I tried to find some hints over the internet, but whatever I got is about checking whether the URL ...
2
votes
5answers
43 views

Append files with bash one-liner?

Currently I use multiple lines to append content into a combined file, e.g. ./myprogram 1.txt > Out.txt # Overwrite for the 1st file ./myprogram 2.txt >> Out.txt ./myprogram 3.txt >> ...
1
vote
1answer
40 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 ...
1
vote
2answers
94 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 ...
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 ...
2
votes
2answers
42 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
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; ...
8
votes
6answers
493 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 ...
4
votes
1answer
120 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 ...
2
votes
1answer
51 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 ...
2
votes
1answer
51 views

How can I get this script file's functions to load without having to source it every time? “command not found” (Bash/scripting basics)

How can I get this script file's functions to load without having to source it every time? I created a file foo with script functions I'd like to run. It's in /usr/bin, which is in the PATH. File ...
0
votes
1answer
195 views

Bash script question - skip enter key press [duplicate]

Here is a portion of my script: read main_menu case "$main_menu" in "0" ) exit ;; "1" ) cp /etc/bamt/cgminer.conf.X11 /etc/bamt/cgminer.conf; sudo mine restart; ...
1
vote
1answer
40 views

Bundling of dependencies with shell scripts

Shell scripts often have to depend on tools that may not be installed on the users' computer. To circumvent this problem, many scripts have multiple fallbacks. IMO doing such things only leads to ...
2
votes
2answers
120 views

How to force watch to run under bash

The problem is that when watch is executed it runs sh and I get this error: sh: 1: func1: not found here is the code: #!/bin/bash func1(){ echo $1 } export -f func1 watch func1
1
vote
1answer
28 views

How to slice a text file into several files of 100 lines each? [duplicate]

My question might be quite unclear here. I have a giant text file with values that looks like this 0.00601233 0.000139403 0.000133679 0.000139497 0.000141683 0.000141888 0.000138646 0.000133465 ...
3
votes
1answer
53 views

Why does the read command not take interactive options when run by sh?

I want to download a provisioning script that reads some configuration parameters via read, and execute it: curl http://example.com/provisioning.sh | sh The problem is, that the read command in the ...
2
votes
1answer
79 views

setenv not working in tcsh

I am trying to install a program on my brand-new CentOs. The installation requires setenv, which apparently does not work, not even in the tcsh shell. Can anyone give me some advice? [Anna@anna ...
4
votes
4answers
281 views

what does $* mean in shell [duplicate]

What does $* mean in shell? I have code two function, run_command and run_test, they are called like this: if [ -n "`echo ${GOAT_COMMANDS} | grep $1`" ]; then run_command $* else run_test $* fi ...
3
votes
1answer
66 views

Using inotify to monitor a directory but not working 100%

I have written a bash script to monitor a particular directory /root/secondfolder/: #!/bin/sh while inotifywait -mr -e close_write "/root/secondfolder/" do echo "close_write" done When I ...
2
votes
1answer
79 views

Accumulate Filename in a Log file using shell script

I have files with their names as ABC_-_123321.20140505_-_161500.CSV ABC_-_654145.20140506_-_135020.CSV String_-_SerialID.Date_-_Time.CSV StartDate, StartTime, EndDate and EndTime are given as ...
1
vote
2answers
64 views

sh + how to use array in sh script in order to print all values in array

I want to use arrays in my sh script. My target is to create an array with the values a b c and print all values in the array. I succeeded to print each array, but I failed to print all values in ...
2
votes
1answer
48 views

Displays and their relative position in a shell script

I want to get information about the displays, something like xrandr, but with more info. I want to know their position. So if I have two or more displays connected I want to know how they are ...
2
votes
1answer
40 views

Extracting lines around keys from a file

I have a large file with around 15 million lines. The odd lines contains the keys (but not only the keys) and the even lines are the data. That is, the file is something like: WRTZ Tyrosine ...
1
vote
2answers
51 views

list files and store it in variables

im new with shell programming. my goal is to give the user a selection which file should be run. i catch all available scripts in one var with: var=$(find script*) so far so good.. this is the ...
3
votes
4answers
183 views

How to cut everthing until a specific word / after a find in a script

Hello I try to get the output of files from today wich contains ERROR. I use this to find the files I want: find /home/user/logfilesError/ -maxdepth 1 -type f -name "gandalf_*"\ -daystart -mtime ...
1
vote
3answers
521 views

Difference between ls -l and ll?

I'm relatively new to programming as a whole and some tutorials have been telling me to use ls -l to look at files in a directory and others have been saying ll. I know that ls is a short list, but ...
0
votes
1answer
132 views

How do I cat a command file?

I have the output of the crontab -l stored in a file (crontab_file) with no extension. But whenever I try to cat it, I get errors saying command not found for multiple line of the file. Here is the ...
28
votes
3answers
2k views

What does `{ { (exit 1); exit 1; }; }` mean?

I quoted the next code snippet from config.status generated by configure. if test ! -f "$as_myself"; then { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5 ...
2
votes
1answer
86 views

Why is my tar in a script behaving different than using tar manually

I'm writing a backup script for my email and cloud service. For simplicity, I only posted the mail-backup part here. Basically, I have a Host-Machine with some Virtual Boxes running in it. These ...
0
votes
1answer
41 views

Scripting error after bc command

I am trying to execute script contains the following: #!/bin/bash USED=`free -m | more | grep -v total | head -1 | cut -d':' -f2 | cut -d' ' -f18` CACHE=`free -m | more | grep -v Swap | tail -1 | cut ...
0
votes
0answers
60 views

Specific Jar file doesn't run on startup

I want to run a jar at startup, so I asked a question here. I was given a few suggestions, so I started from trying to create a script file and desktop file. I created a script file and desktop file ...
2
votes
2answers
340 views

How to get previous year and previous month in solaris 8

How to get previous year and previous month in solaris 8? I have tried below command but none of them is correct: date +'%m' -d 'last month' date +'%Y' -d 'last year'
5
votes
2answers
136 views

How exactly does `if $cmd ; then $cmd ; fi` differ from `$cmd && $cmd`?

In an answer to another very good question I made the following assertion: According to my reading of the POSIX specs, the use of one or the other makes no difference from a parsing standpoint. ...
9
votes
4answers
853 views

Bash syntax error when “else” follows an empty “then” clause

Why would following script not execute, but give a syntax error of else: LOGS3_DIR=~/logs if [ -d "$LOGS3_DIR" ]; then cd cd "$LOGS3_DIR" echo "$LOGS3_DIR" for filename in `find "." -mtime 1 ...
2
votes
3answers
116 views

grep on a Java Method

Lets say I have a java class called DirectAction some of the methods in the class have the word "action" or "Action" What is the grep command to get the names of all the methods who have "Action" or ...
5
votes
3answers
2k views

Prompt user to login as root when running a shell script

The problem I am getting is, when I enter the command, su - root at the beginning of my shell script file, it prompts the user to enter the password and then does NOT continue with the rest of the ...
5
votes
2answers
143 views

What does ${3#?} do?

I have a script with the following variable assignment: TEST_VARIABLE=${3#?} What does the ${3#?} do?
1
vote
2answers
148 views

Run jar on startup in all *nix based systems

I have a jar file which I need to run at startup in all distros of Linux. My previous question here, gave me an idea a rough idea on X-servers. Since I wasn't able to perform startup, I moved on to ...
2
votes
1answer
108 views

How to create an executable bash script for these commands?

I wish to create an executable bash script that will run the following commands as root, that is, using sudo su iptables-save | awk '/^[*]/ { print $1 } /^:[A-Z]+ [^-]/ { print ...
20
votes
2answers
933 views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
1
vote
2answers
166 views

How to show specific lines from specific columns of a file

First off, I'm not allowed awk, sed or perl. For my assignment I was given a file of employee list: Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles ...
1
vote
1answer
46 views

Use a bash function in a pipelined command

I have a command similar to: ... | sort -u -V. Since some versions of sort do not support the -V flag, I thought it would be great if I made a function that conditionally adds the flag. But, it seems ...