Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).
-2
votes
0answers
24 views
Find occurances of words containing @in each line
How to get the words containing a special character (@) in each line.There could be 'n' number of words in a single line with '@'.I would like to find all words and append the words at the end of the ...
0
votes
1answer
19 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
14 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 ...
-4
votes
0answers
33 views
Help creating a script to identify a person's bank company! [on hold]
I need a script that can copy 2 columns (which are 1 and 4 to be exact) from a file to another (newly created file) with the condition that the 2nd column must be a single character (S) and the 4th ...
0
votes
2answers
38 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
17 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
35 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
31 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 ...
1
vote
1answer
42 views
how to resolve the too many arguments error [on hold]
I am passing a command in shell script to print an output in PuTTYy but am getting too many arguments. Please suggest how to resolve.
check_privilege()
{
echo $1 OR $2 OR $3 OR $4 OR $5 OR $6
if ...
0
votes
0answers
18 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
20 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
27 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
20 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
24 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
60 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 ...
0
votes
3answers
64 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
14 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
35 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
32 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 ...
1
vote
2answers
53 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 ...
1
vote
2answers
43 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 ...
1
vote
1answer
40 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 ...
0
votes
0answers
24 views
im trying to see how to solve this problem [on hold]
echo "Please enter 2 numbers"
read y z
## Main part of the program
x=0
y=0
z=0
while [ $y -gt 0 ]
do
x=$(( $x + $z))
y=$(($y – 1))
wait $x
done
echo $x ## end of program
2
votes
1answer
47 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
3answers
27 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
147 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
21 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
50 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
32 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
43 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
29 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
59 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 ...
5
votes
2answers
87 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
31 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
35 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 ...
3
votes
2answers
386 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
17 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
0answers
31 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
42 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);
...
0
votes
0answers
26 views
How to determine format of date and time of log file? [closed]
I have multiple log files say 15-20.The format of date and time in each log file is different eg.UTC,IST etc.I want to write bash script to determine date and time format of each file.
3
votes
2answers
122 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
47 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
43 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
0answers
33 views
How to open new file and edit its content with bash script? [closed]
My script
#!/bin/bash
find . -name "*.xml" -exec grep "sample_freq\|sensor_sernum" "{}" \;
for entry in *.ats; do
echo $entry
done
<sample_freq>131072</sample_freq>
...
-1
votes
0answers
34 views
replacing values between two files using scripting
I have two files as shown below.
file 1:
frames []:
frames [1]:
intensity = 0.006356559616564358
nFormants = 5
formant []:
formant [1]:
...
0
votes
1answer
27 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
53 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 ...
0
votes
1answer
23 views
how replace from A to B comand bash?
i need again your help
A: ","
B: NEW LINE (DOWN)
file.txt:
...
0
votes
2answers
37 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
29 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 ...