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

learn more… | top users | synonyms (2)

-1
votes
2answers
30 views

Execute vim in a loop [closed]

I am writing a script which will let the user edit more than 1 files. I'm trying to launch vim for every file. I've tried putting the filenames in an array and iterate over every element of array and ...
1
vote
0answers
30 views

How to evaluate commands on the given node of cluster by using plink?

Despite plink (putty link, which provides remote evaluation of commands on remote cluster by using ssh) is Windows application, I hope that You will help me in this question. I have the remote ...
1
vote
2answers
22 views

Error while counting characters in a file

I have a source code to find a number of words and characters in a file: #!/bin/bash w=0 cc=0 for i in `cat $1` do j=$i echo $j w=$(($w+1)) c=`expr $j:'.*'` cc=$(($cc+$c)) done echo "no of characters"...
0
votes
2answers
36 views

Convert bash loop index to floating-point

I need to use the index i in a loop such as for i in {0..10..5} in a floating-point calculation. What is the simplest way to convert i to floating-point? Variations on i=$(bc -l <<< "scale=7;...
5
votes
2answers
242 views

Using expr, $(()), (())

In shell script we can substitute expr $a*$b with $(($a+$b)). But why not just with (($a+$b)), because in any resource it is written that (()) is for integer computation. So we use $(()) when ...
1
vote
1answer
45 views

Need to filter the data on the basis of two column having many to one relationship using awk

I have a big file having 50s columns and 100K of rows delimited by |. Now $2(col 2) has multiple type of $1(col 1) value which means col 2 will be repeated. So I have sorted the file. I need now to ...
4
votes
2answers
56 views

Fix array of incomplete links

I'm writing a bash script that will find links in a page. It downloads the source code from a page and finds links in a tags and stores them into an array, $links. The problem though is that some ...
1
vote
1answer
25 views

Finding change in shared object through bash

Here's my case- I have a package named say foo-1.2.3. I want to know which package it installs. So, I install it in a fakeroot approach and make a list of all files it install in a file called FILES ...
2
votes
1answer
24 views

Source of “gsed: can't read : No such file or directory”?

I have a Bash script that performs a simple substitution on OS X. Here's the reduced case: mkdir vs2005-dynamic cp cryptdll.vcproj cryptest.sln cryptest.vcproj cryptlib.vcproj dlltest.vcproj vs2005-...
2
votes
2answers
85 views

search contents of files that are packed in a zip file

For my school project i have to create a script that allows you to search the contents of files that are packed in a zip file. You can give a "search string" with the script, followed by one or more ...
9
votes
4answers
347 views

Run command in bash after a certain length of time has elapsed?

If I'm executing a long process, is there any way I can execute some time-based commands? For example, I'm running a really long process which runs for roughly 10 minutes. After 5 minutes, I would ...
1
vote
1answer
38 views

Move files several directories up for several directories with similar layout

I have a directory with the following layout (the layout in Directory 1 is repeated in every other Directory <num>): Parent directory Directory 1 some directory another ...
2
votes
0answers
27 views

Shell script which runs mono_service.exe as a background task

When I start an Ubuntu Linux 16.04 process with /usr/lib/4.5/mono_service.exe AudioRecorder.exe it returns right way. But, when I write a bash shell script with one line: exec /usr/lib/4.5/...
-1
votes
1answer
47 views

Sub Directories in sub directory using loop

On my CentOS machine, I need to create a main directory inside which I will have a few sub directories and, inside them, some subsubdirectories. Something like: main_directory->sub1,sub2,sb3.. ...
1
vote
1answer
18 views

whiptail require three numbers before continuing

I have this whiptail form that prompts for user input. Is there a way to force someone to enter three numbers, before allowing him to continue? NUMBERS=$(whiptail --inputbox "Enter three numbers only"...
1
vote
1answer
33 views

`sudo -u user script` does not even have access to /bin/sleep

When running the script bla with sudo -u otheruser ./bla I get an output indicating that this script is run such that no external commands are available: otheruser ./bla: line 3: /bin/sleep: ...
0
votes
1answer
26 views

How to execute scripts in a parent-child behavior in bash?

Suppose I have two scripts named parent.sh and child.sh. The parent.sh script contains bash child.sh line and the child.sh script contains echo "This is the child script". Now, if the user executes ...
2
votes
2answers
106 views

what is the difference between “./command” and “bash command”

I have simple bash script file, it contains only one line: rvm gemset use --create 2.0.0@PRJ_NAME If I run this script with: ./scriptname.sh I get a well-known error message from RVM RVM is not ...
-4
votes
1answer
33 views

Create file with date and information

I want to create a file in a shell script. The file's name should be: MyFile_datetoday.dat Where datetoday is today's date in YYYYMMDD format. The contents of the file should be: nameofmyfile;...
2
votes
2answers
92 views

Change directory without using 'cd' [closed]

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
0answers
72 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. ...
0
votes
2answers
31 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
43 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 ...
1
vote
1answer
16 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 $...
0
votes
2answers
58 views

Create blinking text with echo and escape characters [duplicate]

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 \033[5;31;47mMoreText\033[...
-3
votes
3answers
55 views

Sorting not seeming to work [closed]

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
3answers
754 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 ...
1
vote
1answer
29 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 ...
3
votes
1answer
605 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 ...
-1
votes
1answer
24 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
1answer
24 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 ...
2
votes
4answers
72 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
1answer
20 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?
0
votes
3answers
48 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] [mukumukuko@system/...
1
vote
1answer
53 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
2answers
176 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 $...
3
votes
2answers
45 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 ...
1
vote
2answers
67 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 [closed]

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 ...
3
votes
2answers
67 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 HEAPLOGS="/export/home/${USER}/applog/...
0
votes
1answer
54 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 ...
1
vote
3answers
120 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 ...
1
vote
0answers
27 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
1answer
30 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?
-4
votes
2answers
48 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" ] && ...
3
votes
2answers
88 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 ...
1
vote
1answer
37 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 ...
-1
votes
2answers
36 views

Need help with script for regular expression in bash

Using bash shell I have a regular expression which works fine on data. How do I write that regular expression to segregate data into 3 different cols in bash shell script ? Here is the Regexpression ...
0
votes
1answer
49 views

Run Concurrent Instances of a Command Inside a Shell Script

Let me start this by saying that I'm still learning bash scripting and I'm not aware of many things. If I miss something, feel free to scold me as you please. Onward, I'm creating a simple bash ...
1
vote
1answer
48 views

Bash script SFTPing into remote server and downloading files, cd into proper directory on local machine

I have a cron on my Ubuntu server that runs this bash script daily: #!/usr/bin/expect -f spawn sftp user@ip expect "password:" send "password\n" expect "sftp>" send "cd remote_directory\n" expect "...