Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-23-2005, 04:29 AM   #1
Registered: Jan 2004
Location: Gladstone, Oregon
Distribution: Gentoo 2005; FreeBSD 5.3
Posts: 32

Rep: Reputation: 15
Bash shell scripting question.

I am trying to write a script, the problem is, I need to 'cat /dev/urandom' into a file for a certain amount of time. Since /dev/urandom will never end, the command will never complete and my script will more-or-less halt.

I've been experimenting with background processes. My idea was to send 'cat /dev/urandom > ./blah' to the background, and in the foreground have the shell wait for a certain amount of time then kill the background process.

cat /dev/urandom > ./blah &
sleep 1
kill [backgroud process pid]

I, however, don't know how to tell the script the PID of the background process. I know typing 'jobs' in the shell will output the commands in the background, and I could possibly cut the output of that down with something like awk or sed to just what I need, but that seems overly complicated.

Can anyone enlighten me as to a simple way to do this?
Old 04-23-2005, 05:19 AM   #2
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827

Rep: Reputation: 31
dd if=/dev/urandom of=/tmp/randomJunk bs=1k count=10
man dd will tell you more on the option there, but thats something to get ye started (:
Old 04-23-2005, 03:06 PM   #3
Registered: Jan 2004
Location: Gladstone, Oregon
Distribution: Gentoo 2005; FreeBSD 5.3
Posts: 32

Original Poster
Rep: Reputation: 15
Thanks! I also noticed the command 'head' would print the first lines of a file, which could give me a similar effect. Instead of just saying print gibberish for 10 seconds, I say print 1,000 lines of gibberish. Quite handy.
Old 04-30-2005, 03:52 AM   #4
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
The 'head' command depends on '\n' to determine the end of the line. The output of /dev/urandom isn't lines of text, so the 'head' command in't suitable.

kill -SIGHUP %1
The "%" is shorthand for the job-number.
If you might have other jobs running in the background, you could use ${!}.
${!} refers to the last job.

The bash info manual gives other ways you can refer to a background processes.

Last edited by jschiwal; 04-30-2005 at 04:02 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell (bash) scripting question(s) boxerboy Programming 5 11-08-2005 03:51 PM
Bash shell scripting question. pete1234 Programming 11 09-25-2005 02:59 AM
Bash shell scripting Sco Linux - Newbie 1 11-09-2004 11:58 AM
Bash shell scripting question mehesque Programming 2 07-15-2004 10:54 AM
BASH Shell Scripting Question xianzai Programming 5 03-19-2004 07:50 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:55 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration