Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).
0
votes
0answers
6 views
Modification needs to be done in iptables in case of a bridge between two interfaces is implemented
I have a machine with 2 NICs; eth1 and eth2. Each NIC has an assigned IP address and the traffic between them is controlled using the below script.
#!/bin/bash
SAT_RECV="192.168.200.0/16"
NQ=9
...
1
vote
2answers
27 views
CRON Job To Execute Command On Low Memory
I have a situation where I may need to execute an SAP command line tool hdbsql when memory gets too low (to help clean out the HANA table cache).
I'm not well versed in Unix/Linux, and was wondering ...
2
votes
2answers
112 views
bash: can't set a variable to a solid string [duplicate]
I cannot set a variable with a whole command-string as following:
A="/bin/ps wwwaux"
for a in $A
do
echo "$a"
done
It assigns array instead of solid string somewhy. Could you assist, please.
My ...
0
votes
0answers
39 views
How to turn Diff command into bash script with prompt
I have a list that i've copy and i want to paste it to the shell to give me just the repeated lines.
1
1
3
2
As i read about bash commands i've maded this:
cat > /tmp/sortme ...
2
votes
1answer
109 views
Task not run by crontab
crontab strangely does not execute my script, although the script is running just fine from the shell terminal. I already made sure that scripts are separated from each other by a new line space. ...
1
vote
2answers
35 views
Alignment when printing a series of records
How can I resolve the problem of the tables going to the right. I just want it to be shown under 1.
Here's my script with START added. The alignment has gone wonky now:
while IFS="," read f1 f2 f3 ...
7
votes
1answer
203 views
Know which process does I/O without iotop
On Linux, I want to know which process uses my disk I/O bandwith.
I know I can use iotop but I have a machine where, for various reasons, iotop cannot be installed.
How can I manually get that ...
0
votes
0answers
31 views
awk search for string containing forward slash in variable [duplicate]
I'm searching for a string in a massive XML file. Snip:
<sv:node sv:name="notfound">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
...
2
votes
2answers
33 views
sed replace after matching character
I have to change a properties file containing the property:
ro.product.firmware=0.0.1
with a new value that is coming from a function called in a different section of my bash script. I cannot get ...
0
votes
3answers
120 views
Script to check if file exists and copy
Pretty new to shell script,
want to write script which checks if any file .300 extension exists on /exports/files on server 10.xx.xx.xx. If *.300 exists, move file to /exports/files/arch and send an ...
-1
votes
1answer
29 views
How to duplicate lines in a text (xpm) file?
I'm having some pixmaps like this (36, to be exact):
/* XPM */
static char * hide_active_xpm[] = {
"12 14 3 1",
" c None",
". c #EDEDED s active_color_2",
"+ c #313739 s active_text_color_2",
" ...
3
votes
3answers
71 views
How can I count the number of times a phrase appears in a file, and format it neatly?
I have a log file I am trying to pull data from. It is formatted like so, and lists when certain modules are checked in and out:
19:50:26 (license_manager) OUT: "certain_module" [email protected]
...
1
vote
1answer
30 views
Why does bash try to execute strings in a string substitution?
My script is supposed to take input from a pipe and replace newline characters with commas, using the bash's string substitution:
#! /bin/bash
read -d -r input
echo $input
$input=${input//\n/,}
...
1
vote
3answers
55 views
Find the complement set of an array?
Following from this question, where I wish to extract 10 random lines from a file, I now wish to also have the remaining 90 lines as a separate file.
Since the document has 100 lines, indexing from 1 ...
1
vote
2answers
39 views
Re-print an array in a certain format?
I wish to take 10 random lines of file, which is 100 lines long. First, I randomly generate 10 integers between 1 and 100 (inclusive) with
ind=$(shuf -i 1-100 -n 10 | sort -n)
Then, I wish to use ...
2
votes
3answers
53 views
Specific column level substitution
If I have a file with columnar entries, is it possible to substitute specific entries from a specific columns only and save changes to the same file??
Example a file abc.txt:
SR|FRUITS|COLOR|
...
1
vote
2answers
41 views
Substrings in shell script
Am trying to get a substring from a string but am getting the error: ${curr_rec:3:4}: bad substitution
#!/bin/ksh
get_file_totals()
{
if [ -e "$file_name" ]
then
IFS=''
...
1
vote
1answer
45 views
In ShellScript, how to call a function after completion of function which is already running?
My script involves three shell functions. Two running in parallel. I have to call a third function when the two parallel running function completes it's execution. How to call that third function?
...
2
votes
1answer
46 views
POSIX shell scripting and performance tuning [on hold]
Nowadays, I'm researching for performance tuning for shell scripting , And I have been prevented to POSIX shell scripting, However it's only a standard, But I think it's rathar than standard for do ...
4
votes
1answer
40 views
Settings environment variables from a file
I want to have a file (outside of git) that contains certain environment variables. While a script (which is in git) needs to read them and export to env.
My current implementation works for ...
3
votes
1answer
43 views
BASH: Fifo troubles - seems selective about input
So I am having a problem with a BASH service in Debian 7 that I've been working on for quite a while and that randomly started having trouble with its fifo, or so it seems. It is based on kind of your ...
2
votes
1answer
34 views
How to detect if DE is Unity or XFCE via shell script?
I have a few configuration scripts that I run everytime I install a fresh version of Ubuntu. Recently, however, I migrated to Xubuntu. I would like to use the same script for both distros, since both ...
6
votes
4answers
325 views
How to atomically allocate a loop device?
I am writing some shell scripts to handle some disk image stuff, and I need to use loop devices to access some disk images. However, I am not sure how to properly allocate a loop device without ...
4
votes
6answers
141 views
Append something to each list in a file
I have a file, lists.txt, that looks like this:
// stuff at beginning of file
var list1 = new Array();
i = 0;
list1[i++] = 'a';
list1[i++] = 'b';
...
list1[i++] = 'z';
var list2 = new Array();
i = ...
1
vote
5answers
40 views
Output to variable with an indirect command (eval)
What is wrong with this indirect command when run with eval ?
#!/bin/bash
OS=AIX
host=myhost
CMD_AIX="(o=\`host \"$host\" \`)"
CMD=\$CMD_$OS
echo $CMD
eval echo $CMD
eval "$CMD"
Ouput:
$ ...
2
votes
4answers
102 views
Script to log temperature
I have been trying to write a BASH script to log my raspberry pi's temperature. My plan is to run it as a crontab every 15 mins or something. However I keep getting errors, I think it's something to ...
4
votes
3answers
247 views
How to use printf and %s when there are color codes?
I had these lines:
if [[ $# -eq 0 ]]; then
printf "$fail_color Error - Function: $function, Line: $line_number \n"
printf "do_test: Third parameter missing - expected result\n"
exit 1
fi
This ...
1
vote
3answers
46 views
Find a file with the extension .csv in a directory matching a pattern
I have a folder in which I have many subfolders.
The Root folder name is allCSV and sub foldername is will be like a_date(s), b_date(s), c_date(s) ...
I want a file which is in a_date(s) and ends ...
0
votes
1answer
33 views
cant run dd command on android device
The main objective is to send a splited file to an android and join it back up with a .sh script, the file is splited to 5MB parts but its total size is unknown (trying to make an universal script), ...
5
votes
3answers
195 views
Easiest way to find missing quote in a bash a script?
I have a bash script which is currently 700+ lines long. After a particularly long round of editing, it now errors like so:
./run_me.sh: line 693: unexpected EOF while looking for matching `''
...
4
votes
4answers
142 views
Move files by date into different directory using CLI
I have a large number of pictures from an old hard drive that I'm trying to organize. If I run ls -l, I notice all of these files have a creation date of 2012 or before. Ideally, I'd like to move ...
2
votes
1answer
54 views
Checking if a specific key is pressed in shell script
Is there a way I can check if a specific key is pressed in a shell script which is running in background. Consider I am running a shell script which has to play a play list of songs as soon as I press ...
2
votes
4answers
80 views
Extract two values from the output of a command
I'm using the following command in a script to get synthetic wifi info:
echo "$(
iw dev wlp1s0 link |
grep '^\s*SSID:\s' |
sed -r 's/^\s*SSID:\s//'
) $(
iw dev wlp1s0 link |
grep ...
1
vote
1answer
69 views
Which one works faster - regular operators (such as <,>,=) or using (-lt, -gt, -eq)? and why?
Which one works faster - regular operators (such as <,>,=) or using (-lt, -gt, -eq)? and why?
2
votes
3answers
47 views
How can I prepend and append to each member of an array?
I have an array:
CATEGORIES=(one two three four)
I can prepend to each array member using parameter expansion:
echo ${CATEGORIES[@]/#/foo }
I can append to each array member the same way:
echo ...
0
votes
1answer
41 views
Test variable in a bash case statement
What I want is simply to do something if the first variable of the script is empty, in a case statement.
Unfortunately I spent yet a certain amount of time searching for the solution but didn't find ...
0
votes
2answers
29 views
Timeout function return value
I'm using the timeout function on debian to wait 5 seconds for my script.
Works great but the problem I have is that I need a return value. Like
1 for timeout and
0 for no timeout
How am I going to ...
4
votes
0answers
50 views
Bash Script — ffmpeg not being invoked as expected
I'm working on a bash script to convert my music library to ogg* but executing the right command is somehow eluding me. This is the line that should accomplish it:
ffmpeg -i "${file}" -f flac pipe:1 ...
0
votes
0answers
16 views
Why “killproc” command is unable to terminate a script(whiled loop with inter sleep)? [closed]
How to terminate a whiled loop script using "killproc" without using script's pid?
0
votes
1answer
27 views
PHP script to monitor process and write status to a file
I want to write a php script for monitoring particular process using top command and write into the file.
I use top -p pid for monitoring a particular process and also i write a shell script for ...
3
votes
4answers
47 views
How to get the PID of a sub process across to the parent process in a bash shell script?
My shell script is as following:
#!/bin/bash
./process1 #It will create a sub process: sub_process1
while [ condition ]; do
break
done
kill -9 process1 and sub_process1
In my script, it will ...
19
votes
5answers
1k views
How can I propagate my SSH pub key to a list of servers without having to type my password in over and over?
I was recently given username/password access to a list of servers and want to propagate my SSH public key to these servers, so that I can login more easily.
So that it's clear:
There is not any ...
1
vote
1answer
19 views
Script samba password but securely
I want to script the addition on a samba user and the password.
I have seen solutions similar to the one here
Piping password to smbpasswd
echo -ne "$PASS\n$PASS\n" | smbpasswd -a -s $LOGIN
but ...
1
vote
2answers
34 views
Url Decoding shell script
How can I store the url-decoded string in a variable using shell script
#!/bin/sh
alias urldecode='python -c "import sys, urllib as ul;print ul.unquote_plus(sys.argv[1])"'
...
0
votes
1answer
20 views
Help killing off Process for Mem Leak
I am currently building an Android LP kernel, and have some pretty sweet tweaks already running and built into it.
I know there are numerous LP memory leaks (i've already got the bootanimation one ...
-1
votes
1answer
32 views
Webpage content - search for pattern & save to file
I have a web page, say https://test.salesforce.com. I would like to search for a pattern, e.g. "src" at the beginning of a line in the entire webpage content. If the pattern is found, I need to ...
0
votes
0answers
25 views
Run Loop between starttime and endtime and get data from url
I want to check two conduction and run a loop for every one minute.
There should be three variable start_time, end_time and current_time
Conduction's:
start_time should be greater than ...
2
votes
1answer
43 views
How do I properly escape this long su + sed command?
#!/bin/bash
wineuser=tom
su $wineuser -c "sed -i '$ialias ptgui "wine ~/.wine/drive_c/Program\ Files/PTGui/PTGui.exe\"' /usr/people/$wineuser/config/cshrc.csh"
The acutal line inserted to tom's ...
14
votes
3answers
388 views
Prepare answers for questions of a command
Let's say I want to write a shell script that executes just one command. But this command is poorly designed. It doesn't offer any command line options; instead it asks some questions and waits for ...
1
vote
0answers
42 views
Shell Script to change user shell
I am writing a script that would be invoked to change user shell. The basic requirement is that once user gets authenticated (e.g: thorough some web application) the script would be invoked to set the ...