Programming :: Bash Ctrl+c Tarp And Bash Read With Timeout?

Jan 24, 2010

simple bash code:

Code:
#!/bin/bash
trap "echo 'you got me'" SIGINT SIGTERM # to trap ctrl+c
echo "Press ctrl+c during 5 sec loop"
for ((i=0;i<5;i++)); do

[Code]...

How come code behaves normally and stops when ctrl+c signal is caught and resumes, but after I use at least one timeout read in the code it looks like, if signal is caught again it doesn't pause the execution but skips the loop. If you remove -t (timeout) option from the read, both loops look the same!

View 10 Replies


ADVERTISEMENT

Programming :: BASH: Detecting CTRL+C Being Pressed?

Jan 28, 2010

I am working on a script and I want it to detect if CTRL+C is pressed at any time during the script and have it not Break the script and display a message stating to use CTRL+Z instead. How can I do that?

View 9 Replies View Related

Programming :: Use CTRL+D Signal In Bash Script?

Jan 15, 2010

I am writing a bash script where I need standard Input should be saved in a file and should be terminated by passing CTRL+D signal. Any clue how can I do that in bash script.

e.g.
Enter one line at a time
Press CTRL+D to finish

View 1 Replies View Related

Programming :: Bash To Read Write Registers?

Jun 3, 2010

I have been looking for a script example of reading and writing to the parallel port's data, status, and control registers using bash. I see it done in pascal, tcl, etc. but nothing in bash.

View 5 Replies View Related

Programming :: Bash - Read The Array Dynamically?

Sep 24, 2010

Code:

test=(1 2 3 4 5)
for car in ${test[@]}
do
echo "Element : $car"

[code]....

if variable $car equals 1, new element is added "6" to an array. But i don't know why when i am printing all elements of this array (echo "Element : $car") this element ("6") is not mentioned, but if i make a command which check an amount of contained elements by array it will be 6 elements.

View 14 Replies View Related

Programming :: BASH Read File Once Then Return To Top?

Aug 8, 2010

I have a script that reads part of a line, delimited between the first and second intended part by a colon. Then it "chops" the part after the colon, which are words offset by commas (counting them beforehand so as to catch every word in the string's second part), like this:

Code:

"COLORS.JPG:red,orange,yellow,green,"
(Returning)
red

[code]....

single script that parses/breaks both parts of a line like this "COLORS.JPG:red,orange,yellow,green;blue,indigo,violet," so that the two parts, separated into single words (or two and three words, sometimes with spaces) can be used as single-line annotations and written to JPEG files using Exiv2. So far, I haven't been able to come up with a script that does this without one part of the total string(usually that part after the colon) becoming the first word in the second array. In other words, I look for this:

KEYWORDS:

[ ]red
[ ]orange
[ ]yellow

[code]....

Or vice-versa (ie, the second array winds up as a single-line "member" of the first). I think it's because I'm using a single while read loop to read the text file in which the filenames and substrings happen to be. If there's some way of reading a file once and going back to the beginning to read it again in another while loop, I haven't found it.

View 14 Replies View Related

Programming :: Bash - Read File Without Whitespace?

Mar 14, 2011

I am struggling with Bash scripting at the moment (I can't seem how anyone can write scripts with this language!!!) I have a need at home to have a cron job execute daily to lookup my downloads.txt file, read each url (per line) and download content from that url. Then that entry needs to be removed (well I keep all urls in memory and clear the file afterwards). If an error occurred during the download process, then the url is written to a downloads.err file. I got all the above working except for properly reading the url from the text file without including newline characters. I am using the following to read:

while read url; do
--Do whatever here--
done < downloads.txt

How can I get it not to let the url variable have newline characters?

View 11 Replies View Related

Programming :: Bash Read Method 'defaults'?

Mar 28, 2011

I have a script that will ask the operator to specify whether the script should fetch the bits via FTP or SCP:

Code:
# Specify transfer method
echo "[setup]: Please specify file transfer method [ftp] or [scp]:"

[code]....

View 2 Replies View Related

Programming :: Read Multiple Input With Bash?

May 7, 2010

As I'm starting to learn bash scripting I'm trying to automatize some tasks I usually perform. I have a notification mail I need to send several times a day. It has this structure:

Quote:

Dear user,
blah blah blah blah

You need to contact the following people:

[code]...

To replace "user", I found this:

Code:

read -p "Please enter username: " username
echo "Dear $username,"

Which probe to be very useful with other simple notifications like this. But I don't know how to manage the email addresses as they are usually more than one and could vary from 1 to 10. They should appear one above the other. I found this: "Here is a little work around. The only thing the user needs to do is hit enter without anything else on a line and it will close out"

Code:

#!/usr/bin/ksh
word=a
until [[ $word = "" ]];do

[code]....

I tried to use it and modify for my needs but I failed, I don't realize yet how can I use it. If possible, I would like to use the until loop like the above example just for learning purposes but any other form will be accepted as well.

View 10 Replies View Related

Programming :: Read Multiple Arguments In Bash Script?

Nov 24, 2010

First, I made a simply script which let me download a file from a filehosting site on my server, but I can only put one link there, so I need help how to put multiple links in.Here is my script:

Code:
#!/bin/bash
echo "Enter URL:"

[code]...

View 3 Replies View Related

Programming :: Bash Script 'read' With Default Values

Mar 5, 2010

I have a fallowing simple bash script:

Code:
#!/bin/bash
echo -n "Please insert your name: "
read NAME

[Code]....

It works fine, but is it possible to have default values using bash read(1b)? I mean if user is prompter for sex, he just pushes ENTER and by default 'm' is chosen. Or if user is prompted for hometown and he doesn't insert anything, but just pushes ENTER button, 'New-York' sis chosen by default Are such default values possible in bash?

View 1 Replies View Related

Programming :: Looking For A Bash / Perl Script To Read New RSS Feeds (XML Url)?

Feb 13, 2011

I would like to find something portable that work on all machines. I have hmtl2text installed, and perl and sh.

Anyone would know if someone already made such thing to read new through the console ?

View 1 Replies View Related

Programming :: (BASH) How To Read Multiple Lines From Text File

Mar 11, 2011

For example, I have a text file with data which lists numerical values from two separate individuals

Code:
Person A
100
200
300
400
500
600
700
800
900
1000
1100
1200

Person B
1200
1100
1000
900
800
700
600
500
400
300
200
100

How would I go about reading the values for each Person, then being able to perform mathematical equations for each Person (finding the sum for example)?

View 13 Replies View Related

Programming :: Bash Scripting...read A Value From A File Then Assign To Variable?

Feb 27, 2011

At my wit's end I can't find anything that I understand well enough to use. This is for a Unix class, we are working with shell scripting. File1 has 5 in it and File2 has 100 in it.The teacher wants us to read the values then do the math. This is what I have so far:#!/bin/bashvar1='cat File1'var2='cat File2'var3=`echo "scale=4; $var1 / $var2" | bc`echo The final result is: $var3

View 9 Replies View Related

Programming :: BASH: Read + Define + Modify A Numeric Value From/to A File?

Mar 25, 2010

I want my bash file to read from "input.dat" the two values emin emax. My input file looks like that:

#cat input.dat
!Energies
emin 10.00 !minimum energy
emax 30.00 !maximum energy

Now this seems to be not so hard with the command awk

#!/bin/bash
awk '{FS=" "}/emin/{print $2}' input.dat
awk '{FS=" "}/emax/{print $2}' input.dat

[code]....

So far so good. Now, I want to define two variables (e.g. e1,e2) in the bash file, so that their values would correspond to 00.00 and 30.00, as read from the input file. This one I have not found yet, thus asking for your advice. At the end, writing echo $e1 $e2, I should get 10.00 30.00 This is even harder to me: I want to replace the values emin,emax in a new file "modify.dat" which looks like that:

...
c---- energy interval
emin = 1.00
emax = 2.00
...

with the values e1 and e2 I have in my bash file. In other words, I want to call "modify.dat", find these two lines and replace the numeric values with the e1 and e2. At the end, my file should be like:

...
c---- energy interval
emin = 10.00
emax = 30.00
...

View 3 Replies View Related

Ubuntu Servers :: Writing Init Script - Signals To Kill The Process (Ctrl-C) From A Bash Script And Exit Dtach (Ctrl-`)

Dec 5, 2010

I'm trying to write a init.d script to daemonise a sagemath notebook server. Here's what I've done so far, I've copied /etc/init.d/single for the structure, and tried to use dtach to provide a handle to access the process. However, my main problem is issuing the signals to kill the process (Ctrl-C) from a bash script and exit dtach (Ctrl-`)

[Code]...

View 1 Replies View Related

Programming :: Bash - Ps - Psgrep And Read /proc/$pid Make Script Exit

Mar 22, 2011

I have not been able to write bash to use a PID file to ensure no other instance of the same script is running! All three methods I can think of to see if the PID in the PID file is another instance of the script make the script exit with a return code of 1 but the same commands run at the command prompt work as expected.

The first attempt was:

Code:

The first attempted workaround was:

Code:

The second attempted workaround (with debug to make the following command prompt copy and paste meaningful) was:

Code:

Here's the command prompt session, testing with a stale PID file and then manually running the problem command and it behaving as expected:

Code:

This on Slackware64 13.1 which has bash 4.1.7.

In desperation I tried rebooting but the behaviour was the same.

View 2 Replies View Related

Programming :: BASH Read Text List Zip Files Into A Single Archive?

Jul 22, 2010

AKA "zipping on the fly .. the slow-as-molasses way." The list includes full pathnames to each file, and they're all in subfolders of the same parent folder (which, unfortunately, is not the root folder of the drive or system on which the files reside). A cleaned-up and radio-ready portion of the list looks like

Quote:

.../taiga/ahqr-va-choyvp/bv0884-073.jpg
.../taiga/ahqr-va-choyvp/bv2635-073.jpg
.../taiga/ahqr-va-choyvp/bv3067-175.jpg

[code]....

What I'd like to be able to do is zip all the files in the list into a single archive, to avoid the step of having to copy them to the same location (presumably another folder on the HD) and then zip that folder. I'm more inclined to make provisions about extracting to a single folder at some other time. Is this possible in BASH, or would I have to consider a faster, more robust scripting language such as python or perl?

View 8 Replies View Related

Programming :: Bash - Read User Input: URLs Without The Enter Key Stroke?

Sep 23, 2010

Here's a challenge I've been struggling for months with:

I have a bash script that reads URL addresses of our internal server and then executes some test commands on them. Something like this:

Code:
read -p "Enter URL: " url
sh execute-what-ever-to $url

After copy-pasting the URL the user taps the enter key and the script proceeds, but here comes the tricky part: I want this to work without the need to press the enter key after copy-pasting the URL.

"read -n" does not work in this case, as the URLs vary greatly in length. However, the URLs always end to the same string. They could be like "http://url1/END", "http://url2/END" and so on. So this ending string "END" could be theoretically used to recognize that the whole URL has been pasted.

View 2 Replies View Related

Programming :: Parsing Text Files In Bash / Cant Seem To Read The Array Back?

May 29, 2011

PI'm trying to write a script to list all open ports in the MINIUNPND chain in iptables and use the procotol, port and destination ip to open ports on another router using upnpc.Here is the output of iptables -L MINIUPNPD

Code:
>iptables -L MINIUPNPD
Chain MINIUPNPD (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere 192.168.3.124 tcp dpt:19955
ACCEPT tcp -- anywhere 192.168.3.124 tcp dpt:20054
ACCEPT tcp -- anywhere 192.168.3.130 udp dpt:10654
ACCEPT tcp -- anywhere 192.168.3.121 tcp dpt:29955
code....

No matter what i do i cant seem to remove the first 4 characters from the MYPROT array to leave only the digits. Also i cant seem to read the array back???

I thought it would simply be a loop reading each line and passing the fields in variables, executing upnpc commands i need then moving to the next line of the file until it reached the EOF.

View 12 Replies View Related

Programming :: Bash: Printing The Line Number In Bash Script?

Feb 4, 2011

I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.

View 3 Replies View Related

Programming :: Bash Shell Read User Argument From Command Line And Test It

Aug 29, 2010

Trying to create a small script that will read user's input, test if user entered some input and if not display some message or display a text using user's input.

The script is the following but i get an error saying "[: 6: =: argument expected"

View 12 Replies View Related

Programming :: Reading A Bash Variable In Bash Scripting ?

Nov 26, 2008

I have a config file that contains:

my.config:

Code:

Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.

Here is my parse_cmd script:

Code:

View 3 Replies View Related

Programming :: Run Multiple Bash And Php Scripts From A Bash Script?

Jul 25, 2011

I have written quite a few separate bash & scripts and php scripts that up to now I have run from cron jobs. However I have to estimate how long each takes to run, before running the next and so it probably takes much longer than necessary to run them all. They have to run in order.

Now there are so many I am thinking it would be better to have a master bash script that would run one after the other, but I am not sure how to get the master script to wait before starting to run the next script. Is this possible and is there a command that will make the script wait between bash and php scripts , for them to finish, before running the next?

View 5 Replies View Related

Programming :: Bash: Get Filename And Extension Using Bash?

Jan 9, 2010

I would like to get the filename (without extension) and the extension separately. The best solution I found so far is:

Let FILE="thefilenameofsomefilesfor_instance.txt"

Code:

NAME=`echo "$FILE" | cut -d'.' -f1`
EXTENSION=`echo "$FILE" | cut -d'.' -f2`

I think it would be better to count the len and remove 3 chars to right to get the extension, but it can be macintosh filenames with have 4 chars for extensions.

View 5 Replies View Related

General :: Using Timeout Core Utility In Bash Shell Script?

Oct 12, 2010

I'm using timeout core utility in my bash shell script. The problem I'm facing is I want the PID of the command which is supplied to timeout. Let me explain with the code I'm using:

Code:
#!/bin/bash
timeout 120 ./prog1 &

[code]....

View 5 Replies View Related

Software :: Change Bash Shortcut Keys Such As Ctrl-C?

Jul 5, 2010

I*am using Kubuntu 10.04. I would like to change some of the standard shortcut keys for bash (terminal).

I want:

Ctrl-C to copy the selected text to the clipboard.
Ctrl-V to paste from the clipboard into the terminal.
Ctrl-Z to undo.
Ctrl-Shift-C (or even better, Super-C) to terminate the command.
Ctrl-Shift-Z (or Super-Z) to be the background command.
I*don't even know what Ctrl-V did before, some I*won't worry about remapping it.

EDIT:*I*have no idea what is putting the * char after each "I". Maybe this is a non-breaking space?

View 14 Replies View Related

Software :: Make Ctrl + Backspace Work In Bash?

Jan 18, 2010

I've tried without luck to get ctrl-backspace working to delete the previous word in bash. I edited my .inputrc and tried the following:

"C-": unix-word-rubout
Control-Rubout: unix-word-rubout

I can make it work if I change it to some other sequence (Control-j: unix-word-rubout makes ^j erase the word), but I can't make it work with backspace.

View 6 Replies View Related

Programming :: Bash - Read Content Of File To Variable And Use This Variable In For Loop ?

Aug 21, 2009

I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.

For example:

Code:

Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).

View 6 Replies View Related

Programming :: Bash Shell Script Read File Word By Word?

Jan 21, 2011

I have a output file look like this:
{"test1" : "test2", "test3" : "test4"},

How can I read word by word in each line?This is not working code:

a=0
while read word
do a=$(($a+1));

[code]...

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved