Tagged Questions
2
votes
3answers
63 views
Run a script on multiple shells?
I have two servers one AIX with default shell ksh, the other RHEL with default shell bash.
I have a script that is mounted on both that will run similar commands but for either AIX or Linux. This ...
1
vote
1answer
29 views
Compare file size of multiple files in an array [closed]
Scenario:
Ftp site has 100s of files. Once a day, all the .gz files are copied to an AWS site then renamed. Only the date is kept in the file name.
Some of the files corrupted during copy.
A txt ...
1
vote
4answers
58 views
Delete all but largest file in multiple directories
I have multiple subdirectories in /home/usr/ProjZ/programs/ that each contain multiple (or one) .js files.
What I need to do is delete all but the largest .js file, if the subdirectory contains ...
3
votes
1answer
105 views
Preserve formatting when command output is sent to a variable? [duplicate]
I have a bash script. If I run this command to:
grep for certain patterns,
transform the output,
sort the output
dedupe the output
then I get one grep find per line in terminal
LC_ALL=C grep ...
3
votes
2answers
61 views
split a file, pass each piece as a param to a script, run each script in parallel
I have a words.txt with 10000 words (one to a line). I have 5,000 documents. I want to see which documents contain which of those words (with a regex pattern around the word). I have a script.sh that ...
0
votes
0answers
31 views
bash script loses readonly value after first time thru loop
I have a bash script which seems to lose the value of the readonly constant after the first time thru the for-in loop. For example:
#!/bin/bash
readonly DIR="./groups/"
for output in "${array[@]}"
do
...
2
votes
2answers
32 views
I seem to be “losing” this prompt. What is happening?
I ssh into an ubuntu 12.04 cloud server and start a web server like this (w/ bash):
$ nohup python tserver.py &
[2] 2122
$ nohup: ignoring input and appending output to `nohup.out'
After I run ...
1
vote
2answers
179 views
How to iterate through multiple file extension without caring about case sensitivity?
I've seen various topics on how to iterate through multiple file extensions but in most case, the list is defined.
example:
for file in ${arg}/**/*.{txt,h,py}
do
....
done
As can be seen, ...
5
votes
3answers
190 views
How to iterate through a list of files with spaces that is sorted (case insensitive)?
I am doing this in OSX which uses bash but obviously, not all bash conventions are used so hopefully your suggestion is available to me :)
I have the following files
fun bar1.txt
Foo bar2.tXT ...
2
votes
1answer
30 views
Fetching Remote Windows System Information From Linux Server
I need a script/command that would fetch Windows System Information (Host Name,User Name, Domain, OS Info, Hardware Info, Memory Info, processor Info, etc) by running it on a Linux Server (RHEL 6.5 ...
6
votes
2answers
75 views
Passing arguments from a file to a bash script
I' ve got this situation:
./
./myscript.sh
./arguments.txt
./test.sh
Inside myscript.sh, i have to run the file test.sh, passing to it the arguments contained inside arguments.txt.
myscript.sh is:
...
0
votes
2answers
79 views
Solution to integer expression expected [closed]
So I when I run this code on my mac there are no errors, and it provides me the perfect output. But when I run it on Ubuntu or CentOS i get the following error
integer expression expected
...
0
votes
1answer
30 views
Reusing user input in a script
I have the following script which works:
#!/bin/bash
xfreerdp /cert-ignore /f /v:farm.company.com /d:company.com /g:rds.company.com /u:$(zenity --entry --title="Username" --text="Username") ...
0
votes
2answers
104 views
If UID=1000 continues, else exit
I am wondering how to implement the following in a bash script.
if UID=1000, continue
else exit
confirm choice (y/n)
1
vote
1answer
43 views
Why does the same sed regex (after grep) fail when run in a bash script vs bash command line?
Here's the script. It is successful when I run it from the BASH prompt, but not in the script. Any ideas?
When I say "fails," I mean the sed regex doesn't match anything, so there is no replaced ...
0
votes
2answers
57 views
How to count number of instance of a word starting at another word
I need to grep the MySQL-error log starting at today's date formatted like:
`date +"%y%m%d"` (140710)
And look for all instances of the word partitioned.
I've tried various things to no avail. ...
2
votes
1answer
53 views
diff two directories for changes and format output to use for script
I currently try to monitor two directories and subdirectories for changes in files. The directories contain the same set of files, some of them are changed. So I thought I might use the diff command ...
2
votes
1answer
136 views
What is the difference between filename=${1:-/etc/hosts} and filename=/etc/hosts? [duplicate]
What is the difference between filename=${1:-/etc/hosts} and filename=/etc/hosts?
For example:
filename=/etc/hosts
if [ -r "$filename" ] && [ -s "$filename" ]; then
md5sum $filename
...
0
votes
2answers
83 views
set variable options with dot
I'm trying to interface with a system not managed by me that is doing some Unix command scripts and command to easily execute a job.
There is a variable substitution that doesn't work and I wonder if ...
2
votes
4answers
154 views
How to initialize an array using awk and bash?
I am trying to store values of the first line of a text file into an array. Here is what I have so far:
arr_values=()
awk '
NR==1 {
for (i=0; i<=NF; i++)
...
2
votes
4answers
245 views
Inserting a line in a file only if this line isn't yet part the file
Total newbie to shell scripting, I am searching to create a script to automatically apply some custom configuration to text based configuration files.
In the present case, I am searching to add 2 ...
1
vote
1answer
56 views
Why isn't this XMLStarlet Query Working?
I'm trying to write a simple bash script that parses price info from the ebay developer API search results. Here's an example of XML search results for "Detective Comics 700":
...
0
votes
2answers
31 views
Write log for a false statement of an if condition which returns exit 2
I have a script running every 5 mins with two exits in a condition clause.
#!/bin/bash
date=$(date +%Y)
if [ $date -eq '2014' ]
then
echo "Current year is $date"
exit 0
else
echo "Current ...
2
votes
1answer
70 views
SSH Command behaves differently in Expect Script
I'm using this command on Server1
~# ssh root@Server2 /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
to append the contents of Server2's id_rsa.pub to the authorized_keys of Server1.
It ...
3
votes
3answers
155 views
Howto run interactive commands, as another user
I'm trying to write a bash script that
context switches to another user (root, in this case)
executes a set of commands to i. create a user (interactively prompting invoker for username) then ii. ...
3
votes
2answers
76 views
Error when calling mv with wildcards
#! /bin/bash
error_text=$(tail -n +1 /path/dir/folder/exc/a/update/Abd/ER/* | \
grep 'Warning\|Loaded\|Event')
echo $error_text
nc 10.10.99.45 25 << EOF
ehlo mail.abc.pvt
mail from: ...
3
votes
2answers
99 views
Checking the status of custom services with a script
I have a handful of shell scripts that start WebLogic managed servers. I need to design a master script that does the following:
Executes the shell script for a component\managed server
Checks to ...
0
votes
1answer
56 views
Is there a way of copying only directories and not files in bash? [closed]
I want to copy only directories from a folder on a remote server to my server. Is that possible?
Here is the code I have so far but it copies files and folders:
scp -rq ...
0
votes
2answers
71 views
Simple Script to setenv tcsh or export bash
I am having problems with simple scripting, my Box is CentOS so bash is the default shell, now I wanted to send a line via setenv (tcsh) and would like to make a script that will ask me to input a ...
1
vote
2answers
123 views
Changing user to root when connected to a linux server and copying files
My script is coded in a way that doesn't allow you to connect to a server directly by root. This code basically copies files a server to my computer and it works but I don't have access to many files ...
2
votes
3answers
103 views
Need help to combine 3 split lines of bash script into one single line
The following is what I found after googling:
dpkg --list 'linux-image-*' \
| perl -ane 'BEGIN { $r = `uname -r` or die; chomp $r } print $F[1], "\n" if $F[0] eq "ii" && $F[1] !~ ...
2
votes
3answers
279 views
How to capture error message from executed command?
I was tasked to create an automated server hardening script and one thing that they need is a report of all the output of each command executed. I want to store the error message inside a string and ...
1
vote
1answer
53 views
Can't spawn backgrounded process
My team's using Pallet (think Puppet in Clojure) to automate server provisioning, but running into a fairly fundamental problem: Pallet can execute arbitrary scripts directly on target VMs, but if one ...
4
votes
1answer
39 views
Memory consumption of a script
Is there way to check the memory (physical & virtual) consumption of a script, of course in the moment of its execution.
Calculating the used memory minus the used memory before and after the ...
7
votes
2answers
423 views
Check bash/shell script dependencies
Is there a method/command to check for the dependencies of a bash script?
In other words, a response to this question :
Which libraries should a user install to run the script?
I can do this ...
1
vote
1answer
232 views
Create a iptables rule if the rule does not all ready exist
Hi I've created a script to setup Nagios on my remote servers. My Script checks iptables to see if a firewall rule all ready exists and then is supposed to add the rule if it's not all ready there.
...
2
votes
1answer
24 views
Script. How to sort and move catalogs
I have some trouble writing a script. I don't know how to sort and move catalogs.
#!/bin/bash
while read -r line; do
mkdir "sd/$line"
done < 1a.txt
After reading information from 1a.txt ...
0
votes
2answers
59 views
Different forms of executing a shell script
There are a few similar questions around that I've already seen, but I've come up with something different.
I'm reading this http://www.tldp.org/LDP/abs/html/invoking.html and I got confused when I ...
5
votes
1answer
223 views
Save password in bash script for multiple queries
I would like to know if there is a safe way to only be queried for a password once in a custom bash script, and then save it somehow to be used for later needs. At the end of the script it should be ...
2
votes
2answers
37 views
Capture transcript of program with redirected input and output
A typical interaction for a program I've written might look like this:
Enter command: a_command
Completed a command
Enter command: another_command
Completed another command
I typically run my ...
2
votes
1answer
47 views
Beginner question about bash “for loop”
When I do,
for ((i=0; i<"${ARRAY}"; i+=2))
do
echo $i
echo ${ARRAY[$i]}
done
echo $i works as I expected, also echo ${ARRAY[0]} works, but with $i as iterator i see only blank lines. How ...
4
votes
4answers
409 views
Bash Scripting : Printing column data in the same row
I have written a bash script to calculate the size of a PostgreSQL database and print the output along with the date when the script was executed in a text file. The script code is as follows:
...
3
votes
2answers
56 views
Bash script : help file inside the script or in a different file?
I'm writing a script that has the vocation to be a fully featured program at the end. As far as I know, BASH is enough for his purpose (manage PPA's, kinda like Y-PPA). I would like to know how to ...
6
votes
1answer
194 views
When is it important to write portable scripts?
Most code I write is in PHP. I have recently started learning shell scripting. Most of the resources and tutorials that I've come across are specific to Bash. Some warn about bashisms and some don't. ...
3
votes
3answers
528 views
How can I extract/parse a complete URL from a semi random string?
I'd like to have bash parse/extract a full URL (and only the url) from a random short string.
Examples:
bob, the address is http://www.google.com
or
https://foo.com/category/example.html is up
...
6
votes
2answers
406 views
What's the most efficient way to grep for two completely separate things and assign the values to separate variables?
CentOS 6.x
I want to take the output from curl, grep for two completely separate strings, and assign their respective values as variables. What is the most efficient way to do this (without writing ...
20
votes
2answers
646 views
How do I move all files output from a command?
I have this grep command to find files without the word Attachments in them.
grep -L -- Attachments *
I want to move all the files that are output from that command. How do I do that in bash? Do I ...
0
votes
1answer
68 views
Prompting when redirecting content of script to remote machine
I have simple script:
#!/bin/bash
while getopts ":u:" opt; do
case $opt in
u)
USER="${OPTARG}"
;;
\?)
echo "Unknown flag has been used: -$OPTARG" >&2
exit 1
...
7
votes
1answer
227 views
Parallel execution of bash script
I have a table URL_Experiment in my database (mySQL database). I have 2 million URL links in this table.
For each URL, I am checking if some particular text is present in the URL and updating the ...
1
vote
2answers
63 views
Make Trickle get the correct $PATH
Trickle is a bandwidth limiting program. I have the following script for trickle.
#!/bin/bash
echo $PATH
trickle -s -t 3 -u 200 -d 200 "$@"
I have a script in ~/bin/ that want to run the script ...