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

learn more… | top users | synonyms (2)

9
votes
5answers
305 views

Shell Script: grab string in the middle of the text, sometimes in the beginning

I have a large text file where a part of it looks like this (edited values): JULIANA XXXX006060 LI1033322 THC BRL 730.00 XXXX006296 AA1004737 THC BRL 1,740.00 SANTOS JULIANA XXXX006668 AA1004786 THC ...
3
votes
3answers
34 views

Check piped input on empty spaces and forward it

I want to pipe the output of one command to another script. In this other script I want to check whether the input was empty or just consists of spaces. If this is the case, I'll ignore it. Otherwise, ...
0
votes
2answers
56 views

How to remove new line character at end of line ending with a number?

I am new to scripting. i have a file like that shown below. I want to remove newline character if the line ends with a number (preferably sed or awk). file.txt: some question: 1404241 what's ...
1
vote
1answer
125 views

How to bind bash script to a key combination?

I have a lock-screen script that I wish to execute upon a key combination such as Ctrl+L, but cannot seem to bind the script to the key combination. Is such a thing possible? I gave the script a ...
1
vote
1answer
99 views

Automate textual input to a command from a bash script

My question is quite similar to another one here but not quite the same. I have a sequence of commands to create an ssl key/crt ect. And I want to be able to create an automated, default one. These ...
0
votes
0answers
22 views

Syntax error for a script that will enter two numbers and echo an output?

I have to manually walk through the script, and hand write what the script is doing for each line. My only issue is that I retyped the script as it was given to me, but I keep getting a syntax error ...
0
votes
2answers
46 views

Find the number of all typed commands which include a string , using grep

I'm searching through my bash history log for all the typed (started) commands which included the string x. For some reason, the homework checker always says that the number I'm giving is bigger than ...
0
votes
0answers
18 views

Whats diference between ${X} and $X [duplicate]

I'm using a JetBrains IDE to write some bash-script and it is warning me about $X as variable usage, also the IDE suggest me to replace those declarations to ${X}. I'm little confusing about that, ...
0
votes
3answers
87 views

How to get `pwd` in the shell script that was started by another shell script [duplicate]

startScript.sh is in /root/script/startScript.sh script1.shis in /root/script/test/script1.sh script2.sh is in /root/script/test/script2.sh startScript.sh looks like below #!/bin/bash #some code! ...
0
votes
2answers
48 views

How to automate the mail using shell script

I Need to Automate the script to get a mail. Example when we are running shell script all the files are present or not then if present in mail need to get the message files are present else ...
0
votes
1answer
85 views

Download files from the file with same path directory

I need a simple command/script which allows me to download hundreds of files from the file in the same path structure as on the remote server. For example: ...
0
votes
1answer
81 views

Need to get wget output to log file

I need to run several commands in my batch.sh script (e.g. wget) When I use ./batch.sh | tee logs.log only my script output is written in logs.log but wget output is absent in logs. How I can ...
0
votes
1answer
37 views

Unix addition script

Im currently trying to make a addition command in unix and have come up with the following code: #! /bin/bash #! Add - adds two given numbers together and displays the result "$num1" = $1 "$num2" = ...
0
votes
0answers
22 views

shell script how to pass multiple arguments with a common name [duplicate]

I want to run myscript.sh in this way: ./myscript.sh -g 10.10.26.129 -n 10.10.24.0/24 10.10.48.0/22 n contains multiple arguments, and the number of arguments of n is undetermined. My current code ...
0
votes
1answer
63 views

Shell script using function to display system information sending errors

I'm trying to write a script to keep track of my system information. I want to use "function" in the script and just call the functions out. I'm having trouble with the commands working in the ...
1
vote
3answers
73 views

Split multi paragraphed shell output to multiple variables

I am looking to split multi paragraphed shell results into different variables, Here's a sample output from sensors to illustrate acpitz-virtual-0 Adapter: Virtual device temp1: +41.0°C ...
-1
votes
3answers
141 views

cannot move Directory not empty

Edited due to people want to know more then me just wanting to know how to deal with two directories with same names in different places and move one into another when mv will not allow it if files ...
0
votes
1answer
24 views

Script for backup each DB on server but omit system databases

I have read a lot of post around this topic but I didn't found the one to fit my needs. So, basically I want to make two backups: one at mid day (12 PM) and the other at midnight (12 AM) for each ...
3
votes
1answer
40 views

Removing substrings from a shell variable

I have some string that read like this one here Dio - We Rock-Greatest Hits (2CD) (2004) I use this NewDirectoryName=${NewDirectoryName%'(" ")'* } NewDirectoryName=${NewDirectoryName//[^A-Za-z ]/ ...
1
vote
2answers
49 views

How do I write a bash script that will let users choose the value of the MIRROR environment variable?

I am presently in the process of writing a Bash function that when invoked will ask users to choose from a list of Sabayon's mirrors, but I would like it if each option could include info on the ...
2
votes
2answers
299 views

Curl url txt file, but grep each url seperately from single file

Ok, here's one for you guys that is puzzling me. So I have a text file with lots of url's in it. I'm using curl -K "$urls" > $output to spit the output to my output file. Now for the output of ...
2
votes
2answers
196 views

Insert text in specific lines of a file? with special characters

i know this has been answered several times, but i can't figure out how to use it for my project. i have several php files and want to add a new string between line 11 and 12. this is the string i ...
0
votes
1answer
43 views

how to pass the password of two server in shell

my question is here while am copying the files from one server to another server using the scp command. while am running in putty it was asking for password of two sever machines.Is there any other ...
2
votes
1answer
59 views

What purpose does reassigning a variable to itself via echo serve?

I ran across some bash code during a review that reassigns a variable to itself using echo. The variable is an array. The code basically assigns the variable to itself with `echo $a`. a=(one two ...
0
votes
4answers
149 views

regex - find invalid character

Using regex='^[]0-9a-zA-Z,!^`@{}=().;/~_|[-]*$' in below script file I am checking if a given string has any invalid characters or not. str="$1" regex='^[]0-9a-zA-Z,!^`@{}=().;/~_|[-]+$' if [[ ...
0
votes
4answers
179 views

How to display output of command while also parsing it?

I have two commands, build and deploy. Currently I run build manually, parse its output using my own eyes, and use a value I find in the output as an argument to deploy. The process looks something ...
1
vote
2answers
28 views

Displaying a Date Variable

I am very new to shell programming and have a question. What is the best way to display the date right after it says "Creation date and time: " echo "What is your name?" read name echo ...
1
vote
2answers
120 views

how to copy a file from one server to 2 different severs

I need to copy a file for two different severs using shell script. I tried to use Scp usernameip adress and destination path of the folder
0
votes
2answers
95 views

Shell script using function () not finding command

I'm learning shell scripting and I'm studying how to use function in the shell script. The script is suppose to run as a basic math calculator with two defined numbers by the user. It's suppose to ...
0
votes
1answer
67 views

Regex - script check for allowed characters

I need to check a string and make sure that it does not contain any character outside list of given characters. I wrote one script to test this: str="$1" ...
1
vote
1answer
69 views

Find a “moderately large” divisor of a given number?

After processing some data, I get out a file that has a certain number of data points in it --- one per line. I need to pass these data points on to another tool that will do more number crunching --- ...
2
votes
3answers
129 views

Random number generation in Solaris?

What is the best way to generate random numbers in Solaris? I can not seem to find a good answer for this. Most results do not work in my environment. There is a variable or command RAND that seems ...
11
votes
4answers
356 views

Get the display width of a string of characters

What would be the closest to a portable way to get the display width (on a terminal at least (one that displays characters in the current locale with the correct width)) of a string of characters from ...
0
votes
2answers
178 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', ...
2
votes
1answer
58 views

Share environment variables with www-data

I have a set of environment variables, which is created with a shell script config called from my ~/.bashrc. Having a new user www-data running a local webserver (with lighttpd), I need it to benefit ...
4
votes
2answers
455 views

Disallow execution in home directory

Is there any way to disallow file execution from home director in Linux? My target is to protect my system from malicious scripts etc. Sure, I can remove execution bit with chmod for /home/user and ...
0
votes
1answer
58 views

Imagemagick having trouble escaping shell variables

I have an imagemagick command that is having trouble with the $quote$arcangle and $halfdimension$quote concatenated shell variables I'm passing as strings. Here's the transcript: $> echo convert ...
0
votes
1answer
288 views

How to properly execute a script from desktop on Mint KDE 17.2 and Cinnamon 17.3

I created a simple shell script and copied it onto desktop on the following systems: On Linux Mint Cinnamon 17.3 Beta: It asks me every time whether I want to Run in terminal, which I would like to ...
1
vote
2answers
60 views

Bash compose array with the input of other arrays, respecting a specific loop order

I am trying to generate a new array, with the combination of other arrays, respecting a specific sequence. In pure Bash. Example: numbers=(0 1 2 3 4 5 6 7 8); colors=(red blue green); ...
4
votes
2answers
336 views

Unable to SSH Using a Private Key Through Bash Script

To start with, I apologize if this is a painfully obvious/trivial issue, I'm still learning the ins and outs of linux/unix. I work with a few servers that require access via ssh and private key to ...
2
votes
2answers
619 views

How to make bash built-in “read” ignore commented or empty lines?

(For simplicity I'll assume the file to read is the first argument - $1.) I can do what I want externally with: tempfile=$(mktemp) awk '/^#/ {next}; NF == 0 {next}; {print}' "$1" > $tempfile ...
0
votes
0answers
127 views

Solaris Bash script if condition command + store in variable?

I am trying to make two functions in bash. One function that loops through a directories' contents and makes an md5 hash for each file storing them in an .md5 checksum file in the same directory. The ...
0
votes
1answer
48 views

if statement not working properly

I have a loop comparing strings that it still does not kick it out if it matches. the set up is many different types of file extensions, only want to delete the ones I do not want keeping the ones I ...
0
votes
4answers
70 views

how do I extract the SubDir name 4 deep & put into a Var 4 later use?

I need to know how to get the 4th directory name into the tree. this directory var changes while working through it using a loop, so while the loop is running always updating this directory structor I ...
1
vote
1answer
31 views

how replace from A to B comand bash?

i need again your help A: "," B: NEW LINE (DOWN) file.txt: ...
0
votes
3answers
117 views

Efficient way to start multiple shell scripts from single shell script

This is what my code looks like master_script.sh #!/bin/bash chmod +x * declare -A test=( ["echo1"]="sh `pwd`/echo1.sh" ["echo2"]="sh `pwd`/echo2.sh" ["echo3"]="sh `pwd`/echo3.sh") ...
1
vote
0answers
117 views

How do I convert the complete AMD64 Gentoo Handbook into a PDF from the command-line?

I have been writing shell scripts for converting the AMD64 Handbook of Gentoo Linux to PDF and this is my current shell script: function ghand { # Input 1 is the architecture # Input 2 is the ...
1
vote
4answers
160 views

Execute Linux command only if column in CSV file has a value greater than 1

I am trying to figure out a way to execute a Linux command only if a specific column in my CSV file has a value greater than 1. Sample CSV file: Item,Quantity Pen,1 Pencil,1 Stapler,3 ...
2
votes
3answers
190 views

check if java process is running and re-run if it is not running

On ubuntu 15.04, I am running java app through vnc sessions. I have 8 defined sessions that are started during system boot. My question is, how do I create a script that checks to see if the process ...
2
votes
1answer
91 views

How do I run a script every time “yum update” is run?

I'd like to run a script (let's say myScript.sh) every time a yum update or yum install command is executed. So if I run yum update someprogram then myScript.sh should be executed right after that. ...