Tagged Questions
1
vote
0answers
37 views
When gnu parallel exit,my program also fail
I use gnu parallel to run a bash function. The function just contains the bash script to restart my program. At first, the restart is ok, but when the gnu parallel script exits, my program also fails. ...
2
votes
2answers
42 views
Why is my trap not printing any log message?
What I'm doing is,
trap 'rm -f /path/of/file/fileName.running; echo "TRAPPED & READY";' 1 2 9 15 >> trap.log
I didn't get anything in log & the file which should have been deleted ...
-4
votes
0answers
42 views
“unexpected end of file” error in a bash script [on hold]
#!/bin/bash
APP_FILE="/tmp/name_file.txt"
IPFILE="/tmp/ipaddres_file.txt"
PINGDETAILS="/tmp/ping_results"
NEWFILE="/tmp/new_file"
echo "" > new_file
echo "" > ping_results
serverup_count=0
...
3
votes
4answers
7k views
Appending current date to filename
I'm trying to append the current date to the end of a file name like this:
TheFile.log.2012-02-11
Here is what I have so far:
set today = 'date +%Y'
mkdir -p The_Logs &
find . -name The_Logs ...
11
votes
3answers
460 views
Comparing two strings in Bash
I have the following if block in my bash script:
if [ ${PACKAGENAME} -eq kakadu-v6_4-00902C ]; then
echo "successfully entered if block!!"
fi
The script execution is not entering my if block even ...
2
votes
1answer
451 views
Why is 'kill -9' killing browser as well as server?
I sometimes have to use kill -9 as a last resort to kill my rails server. Unfortunately, I have to do that often enough that I wrote a helper function in my bash_profile to do it.
If I do it manually ...
1
vote
3answers
671 views
Query list of servers for memory/cpu allocated
Running RHEL 6.2, trying to write a bash script to SSH to a list of remote servers, and write the CPUs and Total Memory to a file, one line per host in the following format:
HOSTNAME1 CPUS: 12 ...
0
votes
2answers
45 views
Shell script to work on files in some directory
I am a noob in Linux hence this might come as a silly question.
I have a Windows system, so I downloaded cygwin to help me execute Linux/unix commands. I need to execute a shell script on a bunch of ...
2
votes
5answers
39 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 >> ...
0
votes
2answers
30 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 ...
0
votes
0answers
22 views
Portable development environment setup script [closed]
I'm a developer who works on OS X machines. Like anyone, there's a lot of customization and changes that I've applied to my environment. For example:
.vimrc file
.profile file
.gitconfig file
Xcode ...
0
votes
1answer
51 views
Reject SSH connections from unlisted countries, using hosts.allow/hosts.deny on CentOS
I was trying for few hours to make my custom script work when using hosts.allow/hosts.deny, to prevent connections to SSH and other services supporting TCP wrappers from unlisted countries.
Example ...
1
vote
2answers
40 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 [email protected]
I know I can ...
1
vote
1answer
29 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
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
6answers
9k 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 ...
6
votes
3answers
144 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 ...
0
votes
1answer
67 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 ...
6
votes
1answer
1k views
Can't indent heredoc to match nesting's indent
If there's a "First World Problems" for scripting, this would be it. Mainly asking because I feel like I should know how to get around it if I need to.
I have the following code in a script I'm ...
2
votes
2answers
36 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 ...
3
votes
1answer
35 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 <<< ...
3
votes
1answer
74 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" ...
2
votes
3answers
14k views
How to append multiple lines to a file with bash
I am writing a bash script to look for a file if it doesn't exist then create it and append this to it:
Host localhost
ForwardAgent yes
So "line then new line 'tab' then text" I think its a ...
0
votes
1answer
41 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
399 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 ...
2
votes
4answers
100 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 ...
1
vote
1answer
35 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 ...
-4
votes
3answers
65 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
1answer
393 views
KSH styling text based menu using STDERR
Is it possible to format the STDERR in order to have a better looking menu using the select command?
I have a simple select
select oChoice in $(<tempMenu.menu) ; do
case "$oChoice" in
...
0
votes
1answer
53 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 ...
2
votes
3answers
62 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 ...
12
votes
5answers
4k views
How can I get bash to exit on backtick failure in a similar way to pipefail?
So I like to harden my bash scripts wherever I can (and when not able to delegate to a language like Python/Ruby) to ensure errors do not go uncaught.
In that vein I have a strict.sh, which contains ...
2
votes
3answers
98 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 ...
4
votes
1answer
114 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
55 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
2answers
82 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 ...
2
votes
1answer
55 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 ...
8
votes
3answers
406 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 ...
1
vote
2answers
180 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
191 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 ...
6
votes
3answers
347 views
How you stop 'wget' after it gets a 404?
If you use brace expansion with wget, you can fetch sequentially-numbered images with ease:
$ wget 'http://www.iqandreas.com/sample-images/100-100-color/'{90..110}'.jpg'
It fetches the first 10 ...
-4
votes
2answers
102 views
“bash: [: : integer expression expected” [closed]
I want this function to return one random word if there aren't any command-line arguments.
I am modifying linuxconfig.org's random-word generator to run even when #$ -ne 1.
function random-word {
...
2
votes
1answer
30 views
Fetching Remote Windows System Information From Linux Server
I need a script/command that would fetch Windows System Information (Host Name,User Name, Domain, OS Info, Hardware Info, Memory Info, processor Info, etc) by running it on a Linux Server (RHEL 6.5 ...
4
votes
6answers
185 views
Finding the number of time a particular number in a file where range also specified
I have a file with numbers separated by ,(comma). In between it also contains a number range like 300-400. Say for example I have a text file, namely testme.txt which looks like,
...
6
votes
2answers
75 views
Passing arguments from a file to a bash script
I' ve got this situation:
./
./myscript.sh
./arguments.txt
./test.sh
Inside myscript.sh, i have to run the file test.sh, passing to it the arguments contained inside arguments.txt.
myscript.sh is:
...
1
vote
1answer
454 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 ...
2
votes
1answer
65 views
Asteriks in filename as wildcard not working [closed]
So I have a folder with many files like 20140720.457812.tmp and I try to count how many lines they have, I tried this:
#!/bin/bash
lines=`more /folder/20140720*.tmp|wc -l`
but I get this error:
...
2
votes
1answer
560 views
How to strip color codes out of stdout and pipe to file and stdout
I have a program that uses printf with some tput mixed in it and I'd like to pipe the output to stdout as well as a file. I'd prefer to use sed since I don't want any unnecessary dependencies on my ...
0
votes
2answers
437 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 ...
3
votes
3answers
473 views
Quote a variable in shell script “if” statement
e.g.
if [ "$FOO" = "true" ]; then
vs
if [ $FOO = "true" ]; then
What is the different? Seems both of two statements also works.