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

learn more… | top users | synonyms (2)

0
votes
0answers
10 views

Change directory without using 'cd'

I have a list of files with their paths in a text file. And I want to copy these files, mentioned in list, to another directory with their parent folders tree. Also my shell-script to copy these files ...
0
votes
1answer
43 views

how to export name of logged in user correctly?

I have the following script here. #!/bin/bash #some initial variables DLURL=https://raw.github.com/horvan/drubuntu/master DIRURL=/opt/.drubuntu #Get files to run the installation wget -O ...
0
votes
0answers
32 views

Count and compare files in Linux

I want to just compare the number of lines in two files. Below is the list of names of files. One file contains names/location of fastq files; the other file contains names/location of bam files. ...
9
votes
3answers
624 views

How do you remove dot character from string without calling sed or awk again?

I have a file called hostlist.txt that contains text like this: host1.mydomain.com host2.mydomain.com anotherhost www.mydomain.com login.mydomain.com somehost host3.mydomain.com I have the ...
0
votes
2answers
24 views

troubles working on a script with $# and a loop

i have the following script: #!/bin/bash for ((i=1; i<=$#; i++)); do if [ ! -d $i ] then echo $i its not a directory >> file.txt else ...
0
votes
2answers
25 views

simple for loop script to build out ipv6 subnet

I am trying to use nmap to scan a /119 IPv6 network. (512 addresses). Before I do this I want to generate a file that will populate all of the ip addresses in that range. The network info is as ...
0
votes
2answers
51 views

Create blinking text with echo and escape characters

I have learned about formatting options used in shell scripting, which go like this: \033[37:40mAnyText\033[0m Now I want to echo some text like this: echo -e "SomeText ...
1
vote
1answer
12 views

Alias folder of executables with prepended keyword

I have several executable files in a folder /opt/chefdk/embedded/bin/. Examples are ruby bundler chef. Ideally I want to be able to run these files by simply prepending the keyword chef-$1 or chef ...
-3
votes
3answers
52 views

Sorting not seeming to work [on hold]

I am currently writing a webcrawl bot. It generates a list of URLs, and I need it to remove duplicates, and sort the lines alphabetically. My code looks like this: #! /bin/bash URL="google.com" while ...
11
votes
1answer
164 views

Why do these bash fork bombs work differently and what is the significance of & in it?

I get how a normal fork bomb works, but I don't really understand why the & at the end of the common bash fork bomb is required and why these scripts behave differently: :(){ (:) | (:) }; : and ...
3
votes
3answers
2k 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 ...
3
votes
1answer
582 views

How should I handle the shebang when writing my own shell?

I'm writing a script to test a shell project to see that my custom shell has correct output. str="HELLO" echo $str echo "*** YOU SHOULD SEE HELLO ABOVE ***" ls * echo "*** YOU SHOULD SEE THE OUTPUT ...
7
votes
4answers
16k views

Rename files in the local folder adding a prefix or suffix

I have many files in a folder and I want to add either prefix or a suffix (not both) to them. I checked here and found out I can use for filename in *.jpg; do mv "$filename" "prefix_$filename"; done; ...
0
votes
3answers
38 views

Extracting a date from a log file and creating a file with unique dates

I would like to extract from a file the date with format DD.MM.YYYY, date is always in the first place, here an example of the entries 15.04.2016 13:13:30,228 INFO [wComService] ...
0
votes
1answer
16 views

Return Multiple exit status to nagios

I'm trying to write a shell script for nagios plugin. I have a list of failed nodes where I have to trigger a CRITICAL alert to the nagios. Input: #cat file OFFLINE OFFLINE OFFLINE OFFLINE All ...
90
votes
3answers
54k 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 ...
2
votes
4answers
60 views

String Manipulation Shell Script [duplicate]

I am working on a UPS Monitoring project using NUT Server. My objective is to make a shell script which sends one command and in response receives the status and other parameters from the UPS. for ...
0
votes
0answers
14 views

Scripts On Demand [on hold]

Ok this is more like a query. I want to ask if someone knows a platform where I can get bash scripts for system administration. Thanks
-1
votes
1answer
17 views

Move all sub-directory content up one level

My top level directory contains a bunch of sub-directories: af ar ca cs da de el en ... (lots more) Each of these directories has the exact, same structure. They contain two directories: v2.3.0 ...
2
votes
8answers
128k views

Adding two numbers using expr

I'm learning Shell scripting for a diploma in IT I'm currently doing. I'm trying to write a small script that adds two numbers as shown as in one of the tutorials we were given. echo "Enter two ...
1
vote
1answer
45 views

Exiting a shell script if certain child processes exit

I have a Bash script that starts one web server, does some work, and then starts a second web server. I would like the script to exit, and for both of these servers to be terminated, if either server ...
2
votes
1answer
21 views

Set variable to random item in array

In bash, I have an array containing a list of links, e.g. http://xkcd.com/archive http://what-if.xkcd.com/ http://blag.xkcd.com/ http://store.xkcd.com/ I also have a variable named $URL. I would ...
3
votes
3answers
294 views

Sourcing a shell script from within Emacs

I would like to source a shell script that changes my environment variables from within Emacs. That is, I would like the shell script to change the environment in which Emacs runs, and I would like to ...
61
votes
5answers
194k 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
18 views

How to print ${STR1} and $STR2 into a file in bash

I need to print expressions ${STR1} and $STR2 into a file (not the content of the variables).How can I accomplish this using echo or printf?
1
vote
2answers
42 views

Extract zip files into directory based on pattern of zip name

I have these zip files: PLP_633555_2015-03-04_01-12-01.zip PLP_634562_2004-03-02_02-15-07_UBIC.zip PLP_563462_2008-05-02_01-21-03_UBIC_STOC.zip And I need each zip extracted into its appropriate ...
1
vote
1answer
43 views

Get run time for two programs simultaneously

I am trying to make a shell script that could run tests on two differents programs simultaneously and compare their runtime in order to see which one has the best efficiency (tests have to be ...
1
vote
2answers
151 views

Change directory working directory in shell script

I am trying to write a simple shell script, which will change the directory to the shell script directory and echo it. This is the script: #!/bin/bash # cd '/explicit/path/to/script' cd $(dirname ...
1
vote
3answers
113 views

Separating variable names from output strings with no whitespace

I have the following snippet of code where I intend to: Iterate 5 times the loop; get a line from a file (each iteration I need the next line fetched); use the line as a title for a file; put a ...
3
votes
2answers
61 views

Script execution failed

I have created a script to capture the heap and thread dump of a running java process. #! /bin/bash myhost=$(uname) if [ "${myhost}" == "SunOS" ]; then ...
8
votes
3answers
25k views

Recovered deleted files on Mac by command line

I accidentally deleted a file by running: rm -rf ./Desktop/myScript.sh I think it's possible to recover the file, because the rm command removes temporarily. How can I recover the deleted file on ...
0
votes
1answer
51 views

Validate user response in shell script

My shell script is working fine and the files are copying to the remote directory. However I need to check if my INPUT_STRING is starting with S and also check if the files are present in the ...
3
votes
2answers
28 views

Timeout with 'service network restart'

I have a script running on fedora 22 where I am restarting service network as part of a troubleshoot calling service network restart. I want to check if that command is taking too long to execute. If ...
0
votes
1answer
3k views

IBM V7000 scripts for monitoring

Hello (I'm no hard core coder:), I try to develop a script to do some very basic monitoring on an IBM SVC. My goal is to get some information about the nodes and my quroum status and then send ...
1
vote
2answers
49 views

Help me please to find my misunderstanding about this little piece of shell script

Actually, I have a folder which contains several sub folders with lots of images in each. I am trying to gather all the names of the files in each sub folder in a text file (filesNames.txt) in that ...
-2
votes
1answer
23 views

bash shell while loop is going beyond the conditional expression [on hold]

In my problem, it appears like j value and i value reach 6; where i should only run up to 5. Can someone please explain ? i=0; j=0; echo "values of $i and $j" > debug.txt; while [ $j -le 5 ] do ...
0
votes
0answers
32 views

How to do multi threading using mkfifo? [on hold]

I have a file which having milions of records like below. 8350000014|1234567|NULL|NULL 7336004920|478637|NULL|NULL 9876006473|478632|NULL|NULL 6730000012|1234567|NULL|NULL ...
11
votes
1answer
530 views

Is there any way to tell if a shell script was killed with signal 9

I have a bash script (called from a java program) that keeps getting killed. I always catch the signal 15 with trap but then some other signal comes along that I suspect is signal 9 but am in ...
19
votes
5answers
21k views

find n most frequent words in a file

I want to find, say, 10 most common word in a text file. Firstly, solution should be optimized for keystrokes (in other words - my time). Secondly, for the performance. Here is what I have so far to ...
0
votes
1answer
1k views

CSH - How to check if input is NOT number

Please help, I can only see forums with this question for Bash, KSH, and others Need to apply it on csh. to check if the inputted $2 is not number nor the word "all" if ($#argv == 2 && ($2 ...
0
votes
3answers
154 views

Where can I find the shell script for ls command? [on hold]

I am trying to understand how the ls command works, and I presume there is a shell script which defines ls somewhere in the filesystem. This correct? If so, where can I find it?
2
votes
4answers
72 views

How to format a bash loop using sed, awk, grep, and wc

So I have a text file that I need to get extract specific lines out of and count the number of times a number in a specific column appears. I have about 100 or so of these files. I can get it done ...
-4
votes
1answer
41 views

recursive script not working

I am trying to add recursive support to my filegrep script. For some reason this does not work as expected: RECURSIVE_MODE=off # iterate over args for ARG in "$@" do if [ -d "$ARG" ] && ...
1
vote
0answers
21 views

American Fuzzy Lop run test program as unprivileged user or in chroot

I'm attempting to test tcsh on OS X with American Fuzzy Lop as an exercise, but don't want to accidentally clobber any useful files on my system. Knowing essentially nothing about fuzz testing, I did ...
0
votes
0answers
15 views

Unable to execute the rest of my shell script after installing Oh My Zsh [on hold]

I thought that here it will be better to ask for help with my problem. In a nutshell: I'm creating my custom shell script to simply customise my Mac. To make a short example: 1) I install OMZ using ...
1
vote
1answer
27 views

bash script trap for exit and err and logic for difference

I have a bash script and would like to add in the ability to trap for both EXIT and ERR conditions. The structure is currently trap cleanup EXIT function notify(reason) {} function build {} function ...
2
votes
3answers
54 views

Use a wildcard in directory path

I'm trying to write a bash script where part of a directory is a long, unknown string. I know the first part of the directory name. How do I combine the known string and the wildcard in the path? As ...
3
votes
2answers
2k views

Joining bash arguments into single string with spaces

I'm trying to join all of the arguments to a Bash function into one single string with spaces separating each argument. I also need to have the string include single quotes around the whole string. ...
3
votes
2answers
61 views

How can I parse an ini file whose values may contain certain characters?

I have looked at a couple bash ini parsing scripts and I've seen this one used a few times here so I'm trying to see if it will work for me. It looks like it reads the ini file line by line multiple ...
0
votes
1answer
29 views

small error but seems annoying [duplicate]

I have error (command not found). I am newbie here. so what is the easy solution and explanation for this error?