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

learn more… | top users | synonyms (2)

0
votes
0answers
55 views

'cp:cannot access file' error in script?

This is the code: #!/bin/bash $REPORT_PATH='/data/operational/logs' cp "$(`ls -t | head -1`)" "$REPORT_PATH/new_file" This gives error 'cp:cannot access pda_param'. pda_param file is o/p of ls ...
0
votes
1answer
71 views

Shell script printing blank $USER variable when executed by Smartd

I have created a script that smartd daemon (smartmontools) executes as per command below. DEVICESCAN -a -m email -M test -M exec /usr/share/smartmontools/my-script -n stand... Smartd appears to be ...
3
votes
1answer
94 views

Bash scripting to scan files for words and create report

Ok yes this is a homework assignment BUT I am NOT looking to have the answers given to me. The scenario is that I need a script that searches all my users home directories for bad words. I need the ...
1
vote
2answers
81 views

execute a script with some permission

In myscript I have a line that does this : chmod 660 somefile_given_as_argument_to_myscript I gave the members of a group the right to exectute the script. (chmod 770 myscript) but when they ...
1
vote
1answer
33 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
35 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 ...
0
votes
1answer
17 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 ...
0
votes
1answer
39 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
41 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 ...
3
votes
1answer
25 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 ...
0
votes
0answers
125 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
vote
1answer
58 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 ...
-1
votes
3answers
50 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 ...
3
votes
2answers
45 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 ...
-3
votes
0answers
20 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
3answers
41 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 : ...
0
votes
2answers
47 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
2answers
75 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: ...
1
vote
3answers
48 views

How to grep over a variable [duplicate]

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
46 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, ...
1
vote
1answer
64 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
2answers
118 views

Debian autossh boot script not working properly

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 ...
2
votes
3answers
80 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
1answer
32 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, ...
1
vote
0answers
40 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 ...
1
vote
1answer
101 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 ...
2
votes
3answers
68 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 ...
3
votes
5answers
173 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
24 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
92 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 ...
-1
votes
1answer
48 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 ...
0
votes
2answers
38 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 ...
3
votes
1answer
53 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 ...
1
vote
1answer
20 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. ...
0
votes
2answers
71 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 ...
0
votes
0answers
36 views

single jq command with multiple output possible?

I have json log file test.log {"type":"1","fname":"AAA","lname":"bbb" } {"type":"2","state":"gujarat" } {"type":"3","city":"ahmedabad" } {"type":"3","city":"rajkot" } ...
4
votes
1answer
152 views

Can I refer to a global variable even if a locally scoped one exists with the same name?

If I have a variable x total=3 and then a function function A () { local -i total=0 } Is there any way I can update the 'global' total variable total from within function A ?
1
vote
2answers
114 views

use “read” command to pass lines as positional parameters to a shell script

The following file runs, but not doing anything, yet it does not error.... while read dates; do ./avg_hrly_all_final.sh ${dates}; done < ./dates_all.csv I have a list of dates in ...
0
votes
2answers
40 views

I want to print the value from csv file dynamically

I want to print the values from properties file dynamically I am using below code but getting wrong output. testProperty.properties edmcws,edmbws,edmwt Code ...
3
votes
3answers
253 views

spawn - command not found!

I am using Mac OS X 10.9.4, following is my script to copy files from local machine to different host #!/bin/bash #!/usr/bin/expect echo "I will fail if you give junk values!!" echo " " echo "Enter ...
4
votes
2answers
72 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; }' ...
2
votes
3answers
76 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 ...
2
votes
1answer
50 views

attempting to put dynamic input data in a variable via cat method

I'm attempting to write a bash script that should be able to collect data from ttyS0 and put in a variable. I need to talk with a device on the serial line, that is a module able to receive AT ...
1
vote
4answers
87 views

Traverse all subdirectories in and do something in Unix shell script

I am new to bash scripting. I am working on a shell script and got stuck from last 3 days. I want my shell script to visit all subdirectories in a main directory. Do something in directories, sent ...
1
vote
2answers
66 views

Extracting numbers with a decimal point from ls output in Bash

I would like to extract the numeric part of the file names that begin with "hsli" and end with ".h5" in Bash on Ubuntu 14.04.1 64-bit LTS. My ls -l hsli* output is as follows: -rwxrwxrwx 1 ongun ...
0
votes
1answer
16 views

how to find the files in a directory with Prefix__date_030000_1.txt?

how to find the files in a directory with Prefix__date_030000_Suffix here Prefix is the Actual file name and format of the date is date +%Y%m%d and Suffix is the '.txt' and the 030000 number will ...
0
votes
1answer
50 views

Run windows local program from remote linux

I'm trying to run a python script on a remote linux machine accessed by SSH from my local Windows machine. The script contains a loop where for all files in a directory it's going to go to a certain ...
1
vote
1answer
37 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" ...
-3
votes
1answer
45 views

find all .sh files then copy to <date>scriptbackup

Locate all the .sh scripts you have created in your Linux installation (searching recursively if needed – excluding existing backup folders) It will then copy them all into a folder called ...
1
vote
1answer
101 views

Print lines between two patterns matching a condition in awk

How can I print lines between two patterns which meet a certain condition? For instance for an input file partially containing the following: Time %MEM %CPU %SWAP 00:05:02 7.3 ...