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

learn more… | top users | synonyms (2)

2
votes
2answers
622 views

how to add line in a /etc/sudoers file with the help of shell script (50servers)?

Anyone can help me with shell script, I want to know script which can edit /etc/sudoers file and let me add {{{{{userid ALL=(root) ALL}}}} to 50 server I have on same network?
2
votes
3answers
245 views

Exception handling when using tail -f to monitor a log

I have a main script calling the script to do the monitoring. I am trying to catch the exception that the log is missing or not accessible anymore. tail -f is used instead of -F since the logs are ...
0
votes
1answer
1k views

scp stuck when trying to copy files from Linux to windows

I use the following scp syntax in order to transfer a lot of files from Linux red-hat 5 to windows machine (under Temp directory). SSH server is already installed on windows machine. I use this line ...
3
votes
7answers
1k views

Problem in splitting a string using awk or cut command

I have a properties file which has a password field (key value pair) PASSWORD=NDhhHcsOBofXUdUzGw5B0Q== I am trying to get the value in my shell script using the awk command password=`awk -F "=" ...
5
votes
2answers
244 views

Prevent a file from being deleted even after rm -f

I usually stay on StackOverflow but I think on this topic you guys are much more experts here. So today's exercise is weird, I have to write a script.sh and in it do whatever I can to prevent ...
0
votes
2answers
501 views

/dev/null-like automatic trash directory for file moves?

I can (redirect) textual output to /dev/null in order to get rid of it. This is quite handy because this way I can easily enable/disable it in my bash code. Now I have a script that processes files, ...
2
votes
6answers
14k views

How to compare two dates in a shell

How to compare two dates in a shell script? For example something like todate=2013-07-18 cond=2013-07-15 if [ $todate -ge $cond ]; then break fi It doesn't work. ...
3
votes
3answers
474 views

How to delete files only, but keep the directory structure?

I would like to delete every file, but keep the folder structure. Is there a way? NOTE: (I'm using GNU bash 4.1.5).
3
votes
3answers
5k views

Shell script to send an alert mail if disk usage exceeds 90%

I am new to shell scripting and want to implement a script on my server which will automatically send email alerts if the disk usage goes over 90% and second email alert when it goes over 95%. My ...
1
vote
0answers
41 views

FuncName(){} vs function FuncName() {} [duplicate]

There is two ways to define function in bash script. 1. function FuncName() { echo "$FUNCNAME" } 2. FuncName() { echo "$FUNCNAME" } So my questions is what's the different between in ...
0
votes
1answer
227 views

Processing multiple mails in a Postfix mailbox by making cronjob run per second-is that considered good practice?

I need to process at least three thousand incoming emails an hour that are received in a postfix mailbox. Processing involves extracting email attachments and sending the content of an email ...
2
votes
4answers
898 views

Setting a variable whose value depends on another variable

i have a text file variables.txt where i store my variables host=/srv/www/vhosts/hosting index=$host/index.php as you see the second variables depends on the first one. i also have a ...
2
votes
2answers
2k views

Passing a variable to sed

I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script: cat shared.txt sed 's/whatever1/$2 ... whatever2/' > shared2.txt The result in shared2.txt ...
1
vote
3answers
230 views

Couting all characters by BASH character class

I need to efficiently count every character of an arbitrary file by its character CLASS (as defined by the BASH man page); i.e. [[:alnum:]], [[:alpha:]], [[:ascii:]], [[:blank:]], [[:cntrl:]], ...
2
votes
1answer
150 views

Passing values to a parameter in script

Following is the script to copy all libraries of a certain command to make my chroot environment. For example: ./cplb.sh /bin/ls will copy all the libraries of ls command (i.e., the files listed by ...
1
vote
0answers
26 views

Script executed from cron doesn't display GUI notifications [duplicate]

The script below has the name notifyrssh.sh. 1: File=/home/vaios/Desktop/tempcron/liveusers.txt //OK 2: cd /home/vaios/Desktop/tempcron 3: ps -aux | grep sshd > ...
0
votes
1answer
65 views

How do I change working directories with KDialog?

Use-case: I am working in the terminal in /path/with/a/very/long/name and I want to change to some other directory that is deeply nested. But I don't know the path by memory. So I want to browse via a ...
3
votes
3answers
397 views

Determine the last 7 days backup size

Consider I have a folder /home/abdul/backup which contains .gz file for the past 1 year...My requirement is to get the size of last 7 days...
1
vote
3answers
130 views

grep for strings that were found in a previous statement

I'm trying to find out if an address definition is used inside of fortigate configuration file. I extracted the section out of the configuration file, that contains the addresses. In that section the ...
0
votes
1answer
3k views

Formating Mail Body data into html table format

I have a hive query result in tab separated format. I am storing it into a file like query="select Name, age from table;" echo $query | hive > test.csv Now I want to send it in mail using mutt ...
7
votes
2answers
1k views

Optimizing a `while` loop

I have created a mini script to reboot my Raspberry Pi upon the push of a button. The script simply uses wiringPi (gpio command) to set pin 0 (pin 17 in Raspberry Pi standard numbering order) to ...
2
votes
1answer
357 views

Bash nested command substitution not working

Hi I have a bash script that intend to run via watch ./script.sh It's to debug a cooling problem with my laptop, however the script I wrote isn't working as intended. I'm quite new to bash scripting ...
0
votes
1answer
259 views

Pseudo-terminal message in script

This is my script #!/bin/bash exec < filelist.txt while read updatedfile oldfile; do # echo updatedfile = "$updatedfile" #use for troubleshooting # echo oldfile = "$oldfile" #use ...
1
vote
1answer
415 views

How to use kdialog progressbar from a Bash script when the bar was initialized in another script?

Here is an example of how to use the kdialog progressbar. It works. dbusRef=`kdialog --progressbar "Press Cancel at Any time" 10` qdbus $dbusRef showCancelButton true until test "true" = `qdbus ...
4
votes
2answers
2k views

Proper way to add a user account via bash script

I cross posted this question to AskUbuntu because my problem seems most acute on Debian/Ubuntu, but it was suggested that I ask here. Whatever method is suggested for solving this problem should work ...
1
vote
1answer
233 views

Bash script to hide/show files

I prepared a little bash script to toggle the visibility of my hidden OS X files. if (defaults write com.apple.finder AppleShowAllFiles FALSE); then defaults write com.apple.finder ...
1
vote
3answers
1k views

How to execute more than one command in a newly opened terminal?

I have a script that I want to use to open new terminals and type commands in them. A command like gnome-terminal opens a new terminal. Also, if I do gnome-terminal -e myprogram1 it will ...
4
votes
1answer
165 views

How Can I Automate the Change between a Python Script and a Nohup Python Script?

I have a Raspberry Pi connected to a digital temperature probe, which measures my fermenting beer. A python script reads the temperature every second and prints it to the console, and stores it in a ...
2
votes
2answers
59 views

How to paste same information into 2 different files?

I'd like to create two files in /etc/skel using a script which does many other things in addition to the creation of the files in /etc/skel. The part from script regarding /etc/skel looks like this: ...
4
votes
3answers
3k views

bash script error stty: standard input: Inappropriate ioctl for device

I'm using here-documents in a bash script to automate installation and setup where a password is required many times. I enter the password once and the script passes it to the various commands. In ...
7
votes
5answers
2k views

How do I write a retry logic in script to keep retrying to run it upto 5 times?

I want to write logic in shell script which will retry it to run again after 15 sec upto 5 times based on "status code=FAIL" if it fails due to some issue.
4
votes
3answers
1k views

Loop through the lines of two files in parallel

The object of the script I'm making is to compare two series of files. The file names are themselves stored into two separate files, one path per line. My idea is to have two while read loops, one for ...
0
votes
2answers
836 views

Read the output of a command into a variable [duplicate]

I am making a bash script but I'm totally new and got lost. I've made this code cat * | grep "|*parameter1*|" | grep "|*parameter2*|" | cut -f 8,11,12,15,21,23,34 -d "|" | wc -l which works just ...
1
vote
1answer
183 views

Missing “Run in terminal” in KDE

I switched to KDE from Gnome after seven years using the latter. I have everything configured already but I'm missing one option: the run in terminal prompt, when executing a script double clicking. ...
3
votes
2answers
100 views

Bash expansion of ${@} as command

I have a parent script while read cmd do nohup ./script ${cmd[@]} &>> log & done < ~/list that executes this child script while true do eval "${CMD[@]}" #${CMD[@]} ...
2
votes
2answers
488 views

How to password-protect a script on Linux?

How do you set a password to execute a command or script in Linux? I need to avoid a script (in which user and password details are included) from being used/executed from unauthorized users. So is ...
1
vote
2answers
88 views

how to count number of differences in large streams quickly?

I want to count the number of differences (different bytes) in two large streams (devices/files). E.g. two hard disks, or one hard disk and /dev/zero. The program(s) involved must be fast, as fast ...
14
votes
5answers
1k views

Bash in Linux v.s Mac OS

I am buying an iMac. I've been working on Linux for a long time and I do a bunch of bash scripting. I was wondering if all the bash commands and features are available on Mac OS ? Anyone has any ...
13
votes
4answers
2k views

How to make bash abort the execution of a script on syntax error?

To be on safe side, I'd like bash abort the execution of a script if it encounters a syntax error. To my surprise, I can't achieve this. (set -e is not enough.) Example: #!/bin/bash # Do exit on ...
2
votes
2answers
345 views

Having multi lines in bash command substitution

I have a very long bash command inside a command substitution like following: $( comaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaand ) I want to know if there is a way to break this command into shorter ...
1
vote
2answers
122 views

enf of file unexpected (excepting “f$ing ”fi")

os: pfSense (nanobsd) shell: csh script: /etc/rc.conf_mount_rw mount -t msdosfs /dev/da0s1 /mnt/usb if ( -s /var/squid/log/access.log ) then cat /var/squid/log/access.log | perl -p -e ...
1
vote
2answers
3k views

How to return the exit code? Error: return: Reading: numeric argument required

Here's a simplified version of my script. My question is, How do I return the exit code from apt-get in this case? #!/bin/bash install_auto() { apt-get -h > /dev/null 2>&1 if [ $? -eq 0 ] ; ...
3
votes
4answers
2k views

List of servers to check for SSH availability

I have a list of IP address that I need to SSH to and log if I could get to them. I would use a Ping script, but DNS might have already reassigned the address. I do not care about the ones I can't get ...
-1
votes
1answer
100 views

Script to take username and password [closed]

I need to stop few services. whenever we entred the command to stop the service it'll prompt for username and password. We need to automate this whole scenario to take username and password directly ...
2
votes
4answers
912 views

Split long output into two columns

Is there a simple utility or script to columnate the output from one of my scripts? I have data in some form: A aldkhasdfljhaf B klajsdfhalsdfh C salkjsdjkladdag D lseuiorlhisnflkc E sdjklfhnslkdfhn ...
1
vote
3answers
439 views

Renaming or making filenames unique

I have written a plsql procedure using utl file to create files in the temp directory in Unix. I am sending the names of the files to a shell script to mail these files and delete after mailing from ...
0
votes
2answers
180 views

Assigning a value with echo piped together with the bc command and using a variable as an argument

Basically i'd like to assign to variable $finalbyte a value (which consists of a binary representation of a byte e.g 11100000). So trying to do that i put the following as part of some script: ...
0
votes
1answer
518 views

Expression error in bash script

I am getting this really weird error despite of the fact that the same script runs fine on one platform (Arch linux) but not on my other mobile platform (Maemo Linux). I'll pass here the relevant part ...
1
vote
2answers
1k views

Trouble with read line script in Cygwin

I'm on windows 7 using Cygwin. My script and text file are located in the same directory. #!/bin/bash while read name; do echo "Name read from file - $name" done < /home/Matt/servers.txt I get ...
1
vote
0answers
73 views

how to list blocked connections events by the firewall?

So, I used firestarter that had logged blocked connections events with some useful details (but it is not being updated and I found somewhat unsafe as any moment we could click to deactivate the ...