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

learn more… | top users | synonyms (2)

0
votes
2answers
181 views

Creating an automated idle process kill script

I would like to implement a solution to a specific instance of the generic problem wherein idle users tie up resources. I know the user list can be retrieved with w, the associated PID with ps, and ...
0
votes
0answers
7 views

To grab the current proxy that the machine is using in linux environment

I need to grab the below proxy information from all the Linux machines - Proxy Hostname - Proxy IP address - Port - Proxy Serial # - Client IP - Client Logged In As - Groups user is member of I ...
8
votes
1answer
441 views

Why do some Linux shell scripts use exec to run commands?

In a Linux bash script such as: exec /usr/lib/4.5/mono-service.exe ./AudioVideoRecorder.exe "$@" , why do I have to exec the command and not just run it without the exec part?
5
votes
5answers
304 views

What is a fast command line way to switch between multiple directories for system administration?

What is a fast command line way to switch between multiple directories for system administration? I mean, I can use pushd . and popd to toggle, but what if I want to store multiples and cycle through ...
1
vote
1answer
20 views

My backup_system.sh file didn't run under crontab

So i created a script used to backup system, i tested and it worked. Here's the script: #!/bin/bash backup_files="/home /var/spool/mail /etc /root /boot /opt" dest="/mnt/backup" day=$(date +%F) ...
0
votes
1answer
19 views

grepping particular matrix and printing it in single row

I have one file that contains key words word1 and word2 and under word2 there is a matrix as file.dat position1: [ 0.0000000, 0.0000000, 0.0000000 ] word1: 0.0000000 band: - # 1 ...
0
votes
3answers
31 views

Combining several text files into a single csv [on hold]

Input files: File: Article1.txt: paragraph1 It is a long established fact that a reader will...... paragraph2 It is a long established fact that a reader will...... paragraph3 It is a long ...
2
votes
0answers
17 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 ...
1
vote
2answers
17 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 ...
0
votes
2answers
15 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 <<< ...
83
votes
3answers
3k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
0
votes
1answer
34 views

Bash script to add or subtract two numbers from user input

I am very new to Linux and am taking a course in it. Very excited to learn more. I am working on a script that asks user for two numbers, then asks whether user wants to add or subtract. I failed the ...
2
votes
2answers
65 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 ...
5
votes
2answers
196 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 ...
0
votes
1answer
37 views

better multiple replace with curly braces

for a single replace the curly brace works fine but i cant find a solution for multiple replace where is the trick ? or its not possible for multiple replace i use sed and for single the curly braces ...
1
vote
0answers
24 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
votes
2answers
22 views

Execute vim in a loop [on hold]

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
1answer
38 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 ...
2
votes
2answers
87 views

Change directory without using 'cd' [on hold]

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 ...
4
votes
2answers
52 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
28 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: ...
1
vote
1answer
28 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 ...
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 ...
6
votes
4answers
251 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 ...
2
votes
1answer
18 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 ...
1
vote
1answer
1k views

How can I kill child processes with start-stop-daemon?

I'm writing a simple web server using nc and bash. It looks like this: #!/bin/bash rm -f /var/run/streamman/out mkfifo /var/run/streamman/out trap "rm -f /var/run/streamman/out" EXIT while true do ...
0
votes
1answer
17 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 ...
1
vote
1answer
12 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 ...
-1
votes
1answer
38 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.. ...
2
votes
1answer
72 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
31 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: ...
0
votes
1answer
46 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
40 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. ...
11
votes
3answers
674 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
30 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
30 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
55 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 ...
1
vote
1answer
15 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
54 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
171 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
589 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] ...
1
vote
1answer
17 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 ...
92
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
63 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
15 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
18 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 ...