LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script for waking bluetooth (http://www.linuxquestions.org/questions/linux-newbie-8/bash-script-for-waking-bluetooth-591716/)

trox 10-14-2007 12:16 PM

Bash script for waking bluetooth
 
Hi all,

I am trying to make a bash script that does not let my k700i fall asleep, thus disconnecting the bluetooth connection.

The script needs to be something like this:

#!/bin/sh

su

password

hidd --connect 00:12:EE:47:5A:92

exit

I don't know the correct syntax. Any help is greatly appreciated!

Thanks,

trox

The_JinJ 10-14-2007 12:47 PM

Have a look at sudo and /etc/sudoers - it wouldn't be wise to ever pass a root password in a script that can be read by anyone and it will prompt you for the password
With sudo you could have a user run a command as another user - this is done by editing /etc/sudoers - some examples should be at the bottom of the file

ray_80 10-14-2007 01:21 PM

Quote:

Originally Posted by trox (Post 2923814)
Hi all,

I am trying to make a bash script that does not let my k700i fall asleep, thus disconnecting the bluetooth connection.

The script needs to be something like this:

#!/bin/sh

su

password

hidd --connect 00:12:EE:47:5A:92

exit

I don't know the correct syntax. Any help is greatly appreciated!

Thanks,

trox

Drop the 'su' part. Put the script into your init scripts or crontab.

Read up on 'su'. It is not just for switching to the 'root' user:

man su

trox 10-14-2007 01:31 PM

Hi all,

Thanks for your inputs, but I figured it all out. Thank heavens for google. I wrote a bash script which checks for a connection to my phone. Then, I made that script executable and placed it in cron.

Problem solved now my phone automatically asks me to start the desktop remote feature every 20 minutes through the power of cron.

Here is the script:

#!/bin/bash
#script to switch bluetooth phone to hci-mode
/etc/init.d/bluetooth start
hidd --server
hid2hci
#Now we start the connection from the linux machine, no need to press any
#button on the hardware...

hidd --search
hidd --connect 00:12:EE:47:5A:92

Then, the cron job:

20 * * * * /home/ai/./k700.sh

That's all! No passwords needed. I did have to put the cron job in as root though, which is probably why I don't need a password.

Long live the penguin!

ray_80 10-14-2007 01:37 PM

Quote:

Originally Posted by trox (Post 2923866)
Hi all,

That's all! No passwords needed. I did have to put the cron job in as root though, which is probably why I don't need a password.

Long live the penguin!

Good that you have it working. But you didn't need a password for several reasons:

man bash

Thanks for letting everyone know that you got it working and how. That helps someone else with the same problem.


All times are GMT -5. The time now is 10:58 AM.