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

learn more… | top users | synonyms (2)

4
votes
2answers
88 views

Copy the files automatically to destination as soon as created

Is there any way to copy the file in Unix as soon as it is created? I have one location where files will be created in different timings.How can I copy the files automatically using shell script to ...
1
vote
2answers
59 views

How to add all values in an array

I have been stuck on this for way to long now. Tried googling and couldn't find what I was looking for. I simply need to add all the values in an array.(array called packets) I have gotten to the ...
2
votes
1answer
41 views

Capture specific column from command output

I know how to redirect first 5 lines of the output to a file when I execute a command. I want to know how to redirect only specific information from the output. For example I would like to execute ...
0
votes
2answers
63 views

Shell Script: Use “find” to execute shell a command that contains “filename”(without extension) returned from “find”

I have several files with extensions "*.f90" in directory-A. I want to apply the following command for each file in shell script. e.g. filename.f90 f2py -h filename.pyf -m filename ...
10
votes
2answers
119 views

Correct behavior of EXIT and ERR traps when using `set -eu`

I'm observing some weird behavior when using set -e (errexit), set -u (nounset) along with ERR and EXIT traps. They seem related, so putting them into one question seems reasonably. 1) set -u does ...
3
votes
4answers
52 views

How can I make source-highlight colorize .dotfiles by default?

Normally when I cat a file like this it's hard to read without colorizing. I've managed to get cat to use source-highlight like this: cdc() { for fn in "$@"; do source-highlight ...
3
votes
1answer
92 views

Find, count and sort all audio files. ALAC (M4A) files

I'm putting a script together to sort a very large music collection. It's approx 22000 albums, a mixture of FLAC, WAV, AIFF, M4A (AAC & ALAC). So far, I can sort by file type and get a total size ...
3
votes
3answers
183 views

How to use sed command to modify a file's entry line by line in shell script?

This is my file1: #$BQ #{ VOL @home } #database daba #relation tcdeatid #copy 1 #{ version 0 } #opendb #clear #.lruno := 72 #.infno := 1 #.tid.noel := 101 #.tid.info ...
1
vote
1answer
52 views

Why does my bashscript not work?

So I made a bash script to automatically get ts3 installed and running on my vps, but for some reason it doesn't work. The error I get is: > /root/install/ts3install.sh: 4: cd: can't cd to ...
5
votes
1answer
53 views

How to stop a background process started in the same script, without exit the script?

I have a program that takes a variable time to run (no more than two minutes), and to make it less odious, I put fortune messages. #!/bin/bash ... for i in $(seq 1 45); do sleep 3; echo; echo; ...
0
votes
3answers
47 views

Extract value from one file and insert it into another file replacing some other value

I have two files, whose line numbers are not same. But in file1 I want to replace lines taking reference from file2 using sed command. In file1: tid.infno := 72 tid.setnr := 120 (This number 120 is ...
0
votes
2answers
84 views

shell scripting export file

I have output that I need to export to a file. Then I need to call this file to run the script in it. Another condition would be to run the last query or instruction after 15mins. See code below: ...
0
votes
1answer
44 views

Php shell_exec() : for non root user, how to access root command

I have a tricky step to walk for my system (openvpn, 20 clients - raspberries, 1 server CentOS). I want to make an auto install, from clients, for their keys. They call a php page on the server, ...
0
votes
0answers
57 views

(noob) script works from root ssh <-> php shell_exec() does not

A nooby2death question: In a vpn project, I generate keys automatically for clients. I do this with a script file containing : pkitool clientNameForKey This line : - does work if I execute the ...
0
votes
2answers
38 views

How to check option is set to bash script? [duplicate]

I'm creating a basic bash script which deploy a simple webapp. My current code is as follows. #!/bin/bash clear echo "********************************************"; echo "Hello, I'm going to deploy ...
1
vote
1answer
122 views

How to use afl-fuzz (American Fuzzy Lop) with openssl

I am trying to use afl-fuzz with openssl in Ubuntu. A normal usage of afl-fuzz would be: afl-gcc test.c //-- this will produce a.out mkdir testcases echo "Test case here." > testcases/case1 ...
2
votes
2answers
55 views

Getting Group Names for List of Users

I have a text files with a list of users formatted like: name1 name2 name3 ... Calling the command groups gives the primary group name for that user. ex: bash$ groups name1 name1: ...
2
votes
2answers
40 views

Copy certain files from specified subdirectories into a separate subdirectory

I want to copy all .fastq files from every subdirectory that ends in '_CSF' into another already created subdirectory, dir1_CSF. I understand how to copy certain files but not from certain ...
2
votes
2answers
63 views

add filename as text in the corner of an image file

I have a bunch of jpeg images. Say 001abcd.jpg, 002abcd.jpg, and so on. I want to capture the filename and add it as a text in the image itself in one corner. So the result would be, for example, the ...
2
votes
2answers
56 views

Copying new file and sending an email

I want to copy all files with the extension .beta from one directory to another and then send an email with following format. The following files have been moved from directory A to Directory B: 1. ...
4
votes
2answers
104 views

ls -e option not available in linux

I have shell scripts that run on Solaris UNIX that use the -e option on ls to ensure the same format for all files regardless of their age. This option is not available on Linux. The exact same ...
0
votes
1answer
44 views

Mailx -E flag fails

I am using mailx command with -E flag.This is what it says in man page for linux. -E If an outgoing message does not contain any text in its first or only message part, do not send ...
0
votes
0answers
37 views

How to call or execute SCM commands in Shell script

I have a requirement where I need to fetch projects from RTC(Rational Team Concert). I have used SCM commands to connect to RTC and fetch projects from it. I need to call SCM commands from shell ...
1
vote
2answers
104 views

How to see if the directory exists?

How can I check if /bin/x86_64/bin/ls is a directory in a bash shell script Here is what I tried: #!/bin/bash if [ $# -eq 2 ]; then if [[ "$1" = /* ]] then cd ./bin/x86_64/bin/ls ...
1
vote
1answer
46 views

Running a bash script on double click does not have all environment variables [duplicate]

I am running Debian. I have a jar file that I need to execute. A wrapper bash script does a java -jar MyProg.jar. The jar also calls some C code for which LD_LIBRARY_PATH needs to be set. I have set ...
0
votes
0answers
19 views

Export functions to remote or use NFS

We actually write some kind of audit tool for a large infrastructure. We just collect specific (system) information from remote systems in the network. For now, the setup of the tool looks like ...
0
votes
1answer
45 views

Host monitoring script with timestamp

I just made this script for host monitoring. The goal is to ping the host and log the output to a file but also to show output to the terminal. If the host is unresponsive it will log the time with ...
-1
votes
1answer
73 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'; ...
-1
votes
3answers
74 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 ...
2
votes
2answers
61 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
43 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 ...
3
votes
4answers
102 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 ...
4
votes
2answers
64 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
300 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 ...
2
votes
3answers
227 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
15 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 ...
8
votes
2answers
448 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
44 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 ...
2
votes
1answer
56 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
100 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}" ...
2
votes
1answer
69 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 ...
3
votes
6answers
141 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
57 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
3answers
96 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
37 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
40 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
145 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
68 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
153 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
43 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 ...