The bash-script tag has no wiki summary.
2
votes
2answers
42 views
OS X: how to keep the computer from sleeping during a http connection
An application I use downloads data from a specific server, and I need it to sleep after the download has finished and the socket is closed.
However downloads take place at random days, the app that ...
1
vote
3answers
71 views
Creating a file counter that includes hidden files
As part of a programming assignment I need to create a piece of code that will count the number of files and directories (including hidden) recursively. I'm not allowed to use the commands -R, find or ...
2
votes
1answer
65 views
Check for existence of files prior to acting on them
In one of my processes I check for existence of files older than 31 days, and then do stuff with them.
find /my/directory/*txt -mtime +31 -exec ls -l {} \;
All this is well and fine if files are ...
2
votes
5answers
89 views
Bash: What is the use of type (Bash builtins)?
I came across a command in Bash script in which I found:
find /var/log/abcd -type f
The above command was in context of cleaning the log files.
I know what find does.
After having seen -type f, I ...
0
votes
2answers
47 views
Two or more yes/no questions in a script?
I'm writing a bash script which has a "yes/no" question in it, but now I want to have another yes/no question in it. The script can only cope with one yes/no, so how can I have two, or more, yes/no ...
0
votes
2answers
34 views
how to convert float value to int in bash
I will get value like 2743410360.320 and I want value like 2743410360 to a variable.
I tried
INTValueOfGB=$ echo "($gb+0.5)/1" | bc
But I am getting (standard_in) 1: syntax error
2
votes
2answers
66 views
Converting Webserver Logged IP Addresses to DNS
I'm trying to use a bash script to process a webserver log file and replace any IP's it finds with their corresponding DNS hostnames.
An example entry of a single line from the log file is:
...
0
votes
1answer
45 views
Using break command as argument to function [closed]
What about use so solution?
Functions run in loop (cycle?). In that loop - I have another function wuch also uses loop. When second function get NO answer from user - it send break 2 to stop loop and ...
3
votes
2answers
61 views
Running commands after event based outputs
there are commands like
iwevent
or
tcpdump -n src host x.x.x.x
that send to the stdout some lines when something happens. Is there any form of running some command inmmediatly after a ...
0
votes
2answers
48 views
Run level script - Help
I want the following command to be ran, as soon as system boots.
glances -s -P redhat &
How to achieve that?
I tried writing a run level script which didn't work as expected.
1
vote
1answer
81 views
How to assign result of sed to variable
Below is a complete copy of a demo I'm using to to figure out to get the sed command to get rid of the spaces in a persons name, and compress it down to not have spaces.
Once this is done, I want to ...
1
vote
1answer
70 views
What is the use of ; in a single line command?
What does ; mean in single line scripts like this:
while true; do sudo -n true; sleep 60; kill -0 '$$' || exit; done 2>/dev/null &
Does it mean new line, or "next command"?
8
votes
2answers
466 views
Regular expression in bash script
This is my first time bash scripting so I'm probably making an easy mistake.
Basically, I'm trying to write a script that gets the groups of a user, and if they are in a certain group, it will log ...
1
vote
2answers
90 views
Why does this not work when the load average exceeds 1?
I have been testing this script and its behavior has been odd. The script should generate notifications whenever the load average exceeds a specified limit.
Whenever I pass a CPU_LOAD_LMT >=60, no ...
0
votes
1answer
65 views
List of 'if' switches anywhere? [closed]
Is there a list of all the if switches for use in bash scripting? Sometimes I see someone using it and I wonder what the switch they're using actually does.
Example is the -z in this one. I know how ...
3
votes
3answers
111 views
Rename the last 8 characters in filename
I am receiving video files with different names but the final 8 characters of all are numbers (also different every time). This is the pattern of the file name:
custom text 00030402.avi
I have to ...
3
votes
1answer
78 views
How do I fix the argument received from getopt?
I have the following commands in my script:
set -- `getopt -q agvc:l:t:i: "$@"`
...
while [ -n "$1" ]
do
-i) TIME_GAP_BOOT=$2
shift ;;
...
sleep $TIME_GAP_BOOT
When invoking the script ...
1
vote
1answer
42 views
Scrot command - how to save only thumbnail
I'm using scrot to take screenshots from terminal.
However when I want to generate thumbnailed version using parameter -t, I got two files: screenshot.png and screenshot-thumbnail.png.
How can I ...
10
votes
5answers
401 views
Bash script to get ASCII values for alphabet
How do I get the ASCII value of the alphabet?
For example, 97 for a?
0
votes
3answers
68 views
bash script check if variable is is [A-Z]
How do I check if a variable is in [A-Z]
I want something like this:
read var
while [ $var in [A-Z] ]
do
#code here
done
How to achieve this?
2
votes
1answer
110 views
download pdf files from using curl
How to download hundereds of .pdf files from http://www.ncbi.nlm.nih.gov/pmc/articles using a loop, for example for the following document ids:
PMC3386155
PMC3625956
PMC3477654
PMC3531051
...
2
votes
3answers
118 views
Use & (ampersand) in single line bash loop
I have been using this command successfully, which changes a variable in a config file then executes a Python script within a loop:
for((i=114;i<=255;i+=1)); do echo $i > numbers.txt;python ...
0
votes
1answer
115 views
How to force google/youtube searches using the bash? [closed]
I am a bit new to linux (using mint). I am familiar with some of the commands and learned a bit how to write shell/bash scripts.
Anyway, I'd like to know how to force the bash to do a Google or ...
3
votes
3answers
173 views
Script to prevent screen blanking using “mouse move” doesn't work
This is my attempt to make a script that will use a "mouse move" to prevent screen blanking while watching videos. I'm hoping to use the value for highest CPU% process in top and if CPU usage exceeds ...
2
votes
2answers
79 views
How can I add an array of arguments inside my rsync call inside a script?
I want to copy a folder to another location, while excluding some specific files
Here is my current script:
#!/bin/bash
if [ -n "$2" ]
then
source=$(readlink -f $1)
destination=$(readlink ...
2
votes
4answers
310 views
SSH exits after quit case in bash script
So I have the following standard script:
#!/bin/bash
PS3='Please enter your choice: '
options=("option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
...
2
votes
0answers
154 views
Script stops command in it with exit 0
When I write a bash script similar to this on RHEL 6,
if [ "$2" = "" ] ; then
echo vip.start: ERROR: no NIC specified
echo vip.start: Need IP and base interface name
exit 1
fi
case "$1" ...
1
vote
1answer
57 views
Execute command supplied by function parameters
I'm trying to create a function method in a bash script that executes a command which is supplied to the method by the paramters.
Meaning somethings like this:
special_execute()
{
# Some code
...
0
votes
2answers
85 views
sed with auto escape character [duplicate]
CommentAppend() {
# Comment line and append line below commented line
local comment="$1" # search this line and comment it
local append="$2" # Append this line below commented ...
0
votes
1answer
68 views
Problem with small bash script
I often run find in my code projects when I make a change somewhere and I have to find where it impacts other pieces of code, so I thought about writing a very small script to make this easier, call ...
3
votes
3answers
109 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).
1
vote
0answers
40 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
129 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 ...
1
vote
2answers
84 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 ...
2
votes
2answers
52 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:
...
14
votes
5answers
758 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 ...
0
votes
2answers
82 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
166 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 ...
0
votes
2answers
79 views
I need to check a list of directories if it contains a directory newer than 1 month before now
Maybe the title is quite confusing so i'll try to explain what i have done until now.
First of all i have build the list of directories i want to investigate with the code below:
...
2
votes
1answer
271 views
Graphically ask for password in a bash script and retain default sudo timeout setting
The sudo -A (SUDO_ASKPASS) option apparently causes sudo to lose the timeout (e.g., timestamp_timeout) setting.
I want to use the sudo -A option but I want to retain the default timeout (e.g., 15 ...
1
vote
2answers
292 views
Find the process id of a java application in a bash script (to see if the target application is already running)
I know there are a million questions on getting the process ID, but this one seems to be unique. Google has not given me the answer, so I hope stackexhange will help rather than close this question.
...
3
votes
1answer
462 views
how to make my bash script look 100% like a GUI app (so user never sees terminal)
I created a bash script using kdialog (and it runs on Kubuntu 12.04). The GUI is used for every user interaction (after the first one). However, the script still has to be launched from the terminal ...
3
votes
1answer
669 views
start autossh reverse tunnel automatically when network comes up
I connect from my home PC thru an Internet server I own to a restricted client (that I also own) using a reverse ssh tunnel.
I have a script that sets up the restricted client to middleman leg of ...
4
votes
3answers
214 views
Change the text on a single line number in multiple text files
Suppose that I have ten bash shell scripts: script1.sh, script2.sh, ..., script10.sh. Initially, all ten files are identical.
Now, I would like to make two changes in each script:
In each file, ...
3
votes
3answers
197 views
Securely feeding a program with a password
After understanding the problem with using a password in the command line, I need to find a way of feeding a program with a password without it being a problem (without the password being recorded ...
3
votes
3answers
367 views
How to remove any string from a file via shell scripts?
I try to remove string from .bash_profile. String is added when my shell script run:
My string at bash_profile as follows:
# for Myapllication
export MYAPP_HOME=/opt/myapp
I want to remove the ...
1
vote
2answers
460 views
Writing starting from a certain line number in a text file
In a bash script I want to write some lines to a text file, but this file has already been used before and there are texts in it. So I want to echo some additional text in it, starting from a certain ...
2
votes
2answers
299 views
Ubuntu Bash - Changing permissions to user files for automating Apache VirtualHost creation
Moved here from AskUbuntu
I currently have a small Ubuntu Server 12.04 machine (test environment) with about 3 non-root users created. Each user has their own public_html directory under their ...
1
vote
1answer
264 views
Guide/help using Dialog with bash scripting
While I understand how to create menus, no guide I've found teaches how to actually link them to commands
I was hoping to have something like:
dialog--clear --title "n00b's spellbook" \
...
2
votes
2answers
144 views
What scripting language can I use to automate a concatenation & zipping process?
For a project I'm doing I need to concatenate and compress (with zip) many (midi) files and compare their sizes. I've thought there must be some language that allows me to do something like this:
...