The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 2 03-17-2009 01:17 AM
Script to Scan proclog files deeprajn95 Shell Programming and Scripting 3 05-12-2008 06:25 AM
Perl script to scan back lines gholdbhurg Shell Programming and Scripting 3 03-18-2008 12:33 PM
Perl script to scan through files gholdbhurg Shell Programming and Scripting 1 03-05-2008 10:53 PM
port scan shell script nrbhole Shell Programming and Scripting 3 01-31-2008 11:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-15-2008
rahulkhn rahulkhn is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 1
hcitool scan via shell script

Hello,

Im new to shell scripting , and i have the following question .

The hcitool scan command returns the bluetooth address of the phone . When it is run the output is something like

Code:
Scanning....
             00:A1:5D:AB:B2:E9  Nokia 6600
Can i get the output in a varaiable in a shell script ?

I tried redirecting the output to a file, as follows

Code:
hcitool scan > addr
But the file only recorded "Scanning....". The remaining part was not saved.

Please help.

Thanks.

Last edited by rahulkhn; 07-15-2008 at 08:02 PM..
  #2 (permalink)  
Old 07-15-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Maybe the second bit of output is sent to stderr instead of stdout? Try hcitool scan > addr 2>&1.

If that works, use this to get it into a variable:

Code:
addr=$(hcitool scan 3>&1 >/dev/null 2>&3 | awk '{print $1}')
The 3>&1 part copies file descriptor 1 (stdout) to a new file descriptor 3. >/dev/null discards stdout, and then 2>&3 redirects stderr to the new file descriptor. This means that the awk process which is next in the pipeline can read from stdin what would previously have gone to stderr.

Last edited by Annihilannic; 07-15-2008 at 09:19 PM.. Reason: typo
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0