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

learn more… | top users | synonyms (2)

0
votes
1answer
19 views

How to send multiple email results to my email in single message

I would like the email results to be delivered to my email in a single message. Can you please tell me how can I do it. Here is a copy of my script below. All 3 email matters should come in single ...
3
votes
2answers
33 views

How to deal with utilities with same name but behave differently between Unix variants?

For some reason, I chose Macbook as my computer to managing remote Linux servers. Sometimes I will encounter troubles with those utilities which have the same name but behave differently between ...
2
votes
1answer
417 views

Can I get the backup option of cp and mv to work with directories?

--backup[=CONTROL] make a backup of each existing destination file The man page does say that it works on file. It doesn't seem to have any effect on directories. Is there anyway to make this ...
1
vote
0answers
7 views

How to Subscribe a Bash Script as a MQTT Client

From my understanding: Client can be any device as long as it has an MQTT library running on it, from a microcontroller to a server, but must be connected to an MQTT broker over any network Broker ...
0
votes
1answer
6 views

I'm trying to deploy with git to a semi-managed vps, need to write a script to change owners

I'm trying to deploy my sites on my company's semi-managed vps server using this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps It ...
6
votes
3answers
1k 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
31 views

Is `grep -P` (Perl/Python regex) portable on most linux distributions

I prefer (Perl/Python Compatible Regular Expressions) regular expressions. man grep: ...., but only work if pcre is available in the system Is this supported on the most common linux ...
1
vote
3answers
27 views

How to can I make Filename Sequencing with the help of Loops

my intention is to keep the code as simple as possible.Here there are 5 files namely A_1.CSV, A_2.CSV, A_3.CSV, A_4.CSV, A_5.CSV The below code retrieves the first row in a CSV file. Code : ...
-1
votes
0answers
9 views

Making a secret to take contents of a file encode it and outputs to a file and to be able to decrypt the message [on hold]

Script names :make secret, read secret makesecret takes the content of the file msg-norm and encodes it and outputs the encrypted message to the file msg-mixed readsecret then decrypts the ...
0
votes
0answers
27 views

Bash script to create montages of images with G'Mic

I need a bash script which will run through a folder of 100s of jpegs and create montages of every 30 images and output the montages with distinct file names. The G'Mic command to create a montage ...
-1
votes
3answers
32 views

Counting files commands in a loop

How can I use ls *.txt | wc as a separate variable so I can use it in a loop afterwards? That is count.files=$(ls *.txt | wc) ... if count.files -ne 2000; then echo "message" fi I have tried it ...
2
votes
2answers
507 views

Script that unpacks a initrd, allows editing of the preseed.cfg and the packs it to cpio and gzip again

I want to program a script that allows what is said in the title. So basically I gunzip the initrd, than unpack the cpio, open vi to allow editing, save, pack with cpio, and gzip again, so nothing ...
1
vote
2answers
43 views

Creating multiple input files by using sed in a for loop

I am a newbie and wasted a lot of time on this so any help is greatly appreciated. Suppose I have a simple Mathematica script file named "a.m" which contains the parameter 'a' with no assigned value: ...
0
votes
1answer
21 views

Parse header in a file and based on the header replace a value in the file

I have a problem I need help with. I'm not very experienced with awk, but it seems to be a good tool for this job. I have the following file Field1|Field2|Field3|Field4|Field5 a|b|c|d|e 1|2|3|4|5 ...
-8
votes
0answers
34 views

didn't et answer so posting it again---Unix script-help needed [duplicate]

I want to make a script in unix .I have 2 files with same structure with pipe as a delimiter. Now first i want to check if column1(eid)-->file1 is present in column1(eid)-->file2,if so then it will ...
1
vote
1answer
1k views

Deleting Non-empty Directory with smbclient

How can I remove a non-empty directory with smbclient? I have tried the following: 1) rm Result: NT_STATUS_NO_SUCH_FILE listing [dir_path] 2) recurse;rm Result: No Error but also nothing ...
3
votes
1answer
13 views

Pipe command output to Yad and also log the output to a logfile

Need to have the process of command typically an update to be shown using yad and at the same time log all the output to a given log file set up. This is what I have apt-get update | yad ...
1
vote
1answer
26 views

Processing output from an sqlite db into a ksh array with spaces

I am querying an SQLite3 database like so: input=$(-separator "," "SELECT field1,field2,field3 FROM table1") and get this result: Red,Yellow is a color,Blue I need to insert this into an array, ...
-6
votes
0answers
49 views

I need some help writing a script in unix [on hold]

I want to make a script in unix .I have 2 files with same structure with pipe as a delimiter. Now first i want to check if column1(eid)-->file1 is present in column1(eid)-->file2,if so then it will ...
-2
votes
0answers
19 views

Want to write a unix script to compare two files with multiple columns [duplicate]

Need to make a script in unix .I have 2 files with same structure with pipe as a delimiter. Now first i want to check if column1(eid)-->file1 is present in column1(eid)-->file2,if so then it will ...
1
vote
1answer
28 views

shell script to auto kill processes matching certain criteria

when running top it shows a couple of processes got nearly 100% cpu usage of the command 'perl' PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 21287 simon 15 0 4141 ...
0
votes
0answers
28 views

Email script not working when executed from by shell script

I have configured s-nail email notifications and I am able to send the email manually as root. If I attempt to send it as non-root user I get the following odd error: Account `gmail' does not exist. ...
3
votes
1answer
34 views

Running a script during booting/startup; initi.d vs @reboot

I am currently trying to understand the difference between init.d and @reboot for running a script at startup/booting of the system. The use of @reboot (this method was mentioned in this forum by ...
-1
votes
0answers
26 views

problem in AWK with Shell scripting [on hold]

Aim : I have 5 .CSV files namely 1. A.CSV 2. B.CSV 3. C.CSV 4. D.CSV 5. E.CSV I just want to copy the header column names from each file and place to another file named Header.csv . Code : ...
2
votes
2answers
47 views

Copy files to a destination folder only if the files already exist. but the source files have a different file extension

Copy files to a destination folder only if the files already exist. but the source files have a different file extension. i.e I have a backup of some files with ".desktop.in" extension and I want to ...
1
vote
2answers
33 views

How to grep over a variable

I have a scenario like VAR = `Some command brings the file path name and assigns it to VAR` For example VAR can have value like /root/user/samp.txt I want to grep command like grep HI $VAR ...
1
vote
1answer
57 views

Shell script `rm -r`: Redirect write-protected prompt and answer “n”

I have a few lines in a shell script whose function is to iterate through directories, match some names, and delete them. Some areas of the file system are write protected and I would like to leave ...
7
votes
8answers
2k views

Is there a unix command that gives the maximum of two numbers?

I was looking for a command to limit numbers read in from stdin. I wrote a little script for that purpose (critique is welcome), but I was wondering if there was not a standard command for this, ...
1
vote
1answer
29 views

remove lines where a field's value is less than or equal to 3 - sed or awk?

I need to remove every line that has a value of 2 or less in the 8th field (column). My data looks like this: 12-31 Airport 189 379 41 49.70946503 -124.91377258 2 2880 30.8 01-01 ...
0
votes
0answers
14 views

Debian start script strips -f from command

I wrote the start script at the bottom of this question to try to get one of my devices to automatically create several remote forwarded ports with my VPS upon boot. (I've stripped the LSB tags to ...
1
vote
1answer
30 views

Specify the type of field to modify in a file

I have a list of clients, "code", "name", "location", "etc" and I want to make a function that asks the employee to give the client's code and then the field he/she wants to change. For example, ...
2
votes
4answers
5k views

Bash script to convert all *flac to *.mp3 with FFmpeg?

I want to convert all *.flac to *.mp3 in the specific folder. This is what I've tried, but not works: # change to the home directory cd ~/music # convert all *.flac files ffmpeg -i *.flac -acodec ...
1
vote
1answer
45 views

loop through multiple folders and perform commands then write to file

I have 10 folders that I want to loop through while executing the following command: awk 'FNR > 1' *.csv | sort -sk 1,2 | sort -sk 3,3 > ${f}_appended.dat With a for loop wrapper, like ...
2
votes
3answers
47 views

Calculate date difference between Last modified date of a file and NOW using shell script

I am trying to calculate the time elapsed since the log file was last updated. I guess following commands will be used lastUpdate=$(date -r myLogFile.log) now=$(date) How can I subtract them and ...
4
votes
2answers
70 views

Use lines in a file to produce string and file name

I have a file, foo.txt, that has a folder name on each line: folder_1 folder_2 folder_3 And I'd like to do something like this: cat foo.txt | xargs -I {} echo 'function {}() { return stuff; }' ...
1
vote
0answers
33 views

Text User Interface

I have been working on a shell script, and was wondering if I can put up a text user interface for the shell script. After some searching, I see few people suggest using "ncurses/curses". However the ...
3
votes
5answers
161 views

Pick the latest file based upon the sequence number given in the file name

I have a requirement, I have few files in a directory, I need to pick the oldest one for processing. For Exp: I have below files in /tmp directory: Sample_0000237826-001_xyz.dat ...
1
vote
1answer
19 views

Record commands only to file

How can I record commands only to a file? I imagine something like the script command, but not recording prompts or the OS response, just the entered commands followed by a line feed. I want to ...
1
vote
1answer
23 views

Handle compress command error messages on AIX

I am working on production issue and unable to reproduce error message for compress command. Current Solution We have case-esac block in shell wrapper that handles messages as follows; case "$MSG" ...
-1
votes
1answer
43 views

Can you please tell me what is wrong in below script?

script : it is giving below error. please help me. basically i need to get email when memory exceeds some limit. error : ./vamsitest.sh: line 10: [: missing `]'   #! /bin/bash # Total memory ...
1
vote
2answers
406 views

Script to su -c into a screen is not working as intended

I'm working on a script that will allow me to load up a screen from a user via sudo and su -c. However, when I use it, it will just show the shell of the user: sudo su -c "script /dev/null; screen -r ...
0
votes
1answer
526 views

Starting Resque worker with script doesnt work, starting by hand does

I am trying to figure out why my process doesn't work if started via a script, but works fine if started by hand. Here's the details: script is a resque worker start script. The script location is ...
2
votes
3answers
67 views

How do I use inserted values using getopts

I have this bash code combined with getopts and if I understood getopts correctly OPTIND contains the index of the next command line option and all the command line options provided to shell script ...
0
votes
2answers
26 views

provide password for script begin called inside another script [duplicate]

I have written a shell script which in turn calls another script, but the second one prompts for password. I want to supply the password and pass the prompt without user begin notified. Here is my ...
1
vote
3answers
1k views

I get a “command not found” error, though the script file is shown by “ls”

I want to run yii console commands in shell. I run protected/yiic in the console, yet it fails, yielding -bash: yiic: command not found What's the problem? See the shell commands and responses I ...
-1
votes
0answers
48 views

I'd like to write shell script to connect to database and delete the records automatically [on hold]

Can you please help me to write shell script which should delete records from my delete query and same will be appear in log file by saying record has been deleted. Also once this is done, it should ...
1
vote
3answers
554 views

Editing INI-like files with a script

I'm writing a script to automate setting up Puppet agent configuration files in Docker. Basically, I need to ensure that the following section is in /etc/puppet/puppet.conf: [agent] ...
0
votes
2answers
43 views

Gzip file but excluding some directories|files and also append current date

I'm looking for a way to create a .tar.gz file from a directory but I have some doubts. I'm know that the command for create the file is: tar -zcvf /path/to/compressed/file.tar.gz /path/to/compress ...
3
votes
1answer
47 views

Edit a file via a script yet maintain the osx tags

On OSX you can have tags which allows you to identify different categories of files. Here are two text files with different tags when viewed in Finder: I have a large number of these files and have ...
0
votes
1answer
13 views

Files missing after using mv and parameter substitution in a loop

Related questions to missing files after mv don't appear to answer my question. The following commands were run within the working directory where the files are located, resulting in missing files. ...