Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).
0
votes
1answer
22 views
How to set Row & Column in shell Script
I am a beginner in shell scripting. Just made 1 script with the help of others and it is working like we expected. However i want to organize it more.
Current Script
{ date '+%F %T';
...
0
votes
2answers
40 views
Need to Split the output in Row & Column
I am just a beginner in shell scripting and currently working on one script which will capture all the Endpoint Name & Ongoing calls on my switch and will send the output to one file.
Output is ...
1
vote
2answers
27 views
Allow another user to run a specific script as my ID
I have a script somewhere in my home directory. I need to give another user or a group permissions such that when they execute that specific script, it executes as though I am logged in and has all ...
1
vote
4answers
32 views
What is the best way to delete files & folders in a directory excluding the contents of one folder? [duplicate]
I'm trying to automate some file house keeping I do pretty often. I want to delete all of the files and folders in a directory while excluding the folder "./xfer" and its contents.
I've bee trying ...
2
votes
4answers
85 views
How do I get the value of a named option of an already running process in Linux?
I run the following command.
ps -e -o args | grep destiny | grep UNIX
I receive the following output.
/path/to/destiny -r -m UNIX -t TCP -p 1501
What command can I use the get the value of the ...
3
votes
2answers
33 views
Mac OS X how to verify particular packages are installed
In a BASH script I need to check if gcc, g++, cpp, make, libpng devel, zlib devel, git, Java (including devel files), ant and pkg-config are available on Mac OS X and if not, I need to prompt user to ...
4
votes
4answers
281 views
Merge two files
I have this file1.txt
deiauk 9
kespaul 8
luktol 7
titkur 6
and other file2.txt
kespaul b
deiauk a
And I want to merge both files in one by first value, so my result should be
deiauk 9 a
...
-1
votes
0answers
19 views
Get variable value in a Shell script [duplicate]
Assume we have a variable:
NAME="StackOverflow"
What is the difference between these ?
$NAME
${NAME}
"$NAME"
"${NAME}"
4
votes
3answers
174 views
How to sort data in the file using script?
I have a file logs.txt with numbers which repeat:
1 QWE
1 ASD
1 QWE
1 QWE
1 QWE
1 qwe
12
22 qwe
2 aaa
2 vcc
2 xxx
4 asa
44 qwe
4 gfd
4 bcx
5
6 kuy
7
76 lol
5
4 ggg
23
...
1
vote
0answers
11 views
How can you recover from disk corruption on a backup drive whilst maintaining all hard links?
So, I have a scenario that is similar to How to copy directories with preserving hardlinks? that I wish to use however I have corruption from the backup hardlink source.
My Scenario:
1. I backup my ...
6
votes
2answers
365 views
Multiple shebangs in a single bash file
I have a script from other person which has a look (note: it's a single file):
#!/bin/bash
some commands
some commands
#!/bin/bash
some commands
some commands
#!/bin/bash
some commands
some ...
2
votes
2answers
37 views
Selecting a random sample from a directory tree
I've got a directory that contains directories that contain directories that contain files. I'd like to select two files at random from each leaf directory. I found this question about selecting ...
1
vote
1answer
22 views
Batch Extract & Repack .RAR Files
I'm dealing with a large amount of password protected .rar files which need to be repacked to remove the password. (The password is known.) I was wondering if there was a script to batch/recursively ...
2
votes
2answers
79 views
Remove first n lines from file with variable
The command below works for deleting the first 3 lines:
sed -i -e 1,3d t.txt
So I tried substituting the 3 with a variable in a script as below
NrLines=$(wc -l t.txt)
sed -i -e 1,"$NrLines{d}" ...
1
vote
1answer
32 views
For Loop for Google Image Downloading Bash Script
I have a bash script which downloads images from Google Images.
This is the command I use:
bash getimages.sh 3 rocky%20mountains
That command will download the 3rd picture in Google Images. To ...
2
votes
6answers
114 views
Extracting lines based on conditions
Each line in a comma-separated file has 5 fields.
a,b,c,d,e
f,g,c,i,
j,k,c,m,n
o,p,c,r,s
t,u,c,w,
x,y,z,aa,bb
How can I extract the lines which have c in the 3rd field and their 5th field is NOT ...
3
votes
1answer
44 views
How do I rename many files from whatever to sequential filenames? [duplicate]
I have a directory with 8,000 images. These have a variety of filenames and are of type jpeg or png.
I want to rename them to:
pic00001.png
pic00002.jpg
I don't mind if I end up doing the pngs in ...
1
vote
4answers
75 views
Script to move one filetype and create a subfolder, if it exists?
I'm trying to find a script that would basically look recusively at a directory, and if the script finds file that are .flac files, it will create a subfolder called FLAC in that same folder, and move ...
0
votes
1answer
19 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; eth0 and eth1. 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
31 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
119 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
2answers
62 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
114 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
36 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
216 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
32 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
34 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
193 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
32 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
72 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
32 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
57 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
42 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
47 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 [closed]
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
41 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
46 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
330 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
145 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
41 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
103 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
252 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
39 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
199 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
146 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
55 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 ...