Android and Linux

Sunday, November 7, 2010

ssh error and fix

I've helped several people with this so I might as well post it here for others to stumble across. ssh can sometimes give this error:

stderr: ssh: Warning: failed creating //.ssh:
Read-only file system
stderr: Host '[my PC's ip address]' is not in the trusted hosts file

For some reason, ssh is trying to create it's hosts file in /.ssh, which is read-only, giving the error. For me, it happened when trying to use it in a script executed through GScript, but I believe it happens in other circumstances as well.

The solution that has worked for me and a few others is to replace the stock ssh binary in /system/xbin with a link to the ssh binary from Better Terminal Emulator Pro. Unfortunately, BTEP costs money but if you're using ssh or anything else from a terminal, I highly recommend buying it.

After you install Better Terminal Emulator Pro, back up the stock binary by typing this in a terminal:

mv /system/xbin/ssh /system/xbin/ssh.bak

Then put a link in /system/xbin to the BTEP ssh binary:

ln -s /data/data/com.magicandroidapps.bettertermpro/bin/ssh /system/xbin

This has been necessary every time I install an update because they always contain the stock ssh binary. Luckily, this fix has worked every time.

Thursday, November 4, 2010

Finally, a use for twitter

I've never had much use for Twitter but I've recently found myself using my phone to log into my computer to check various things throughout the day. While I have those things set up with GScript shortcuts for quick checking, there's no reason I need to manually be logging in to check them.

You used to be able to post to twitter with curl, but not since they switched to OAuth. Now the simplest way is with TTYtter, the command line Perl Twitter posting script.

Once you run TTYtter and set up your login info, you can post to Twitter using ttytter -status="blah blah blah", but I usually like setting up things to use either pipes or argument type input, plus I'll never remember the name ttytter, so I use this little script named "twit"
#! /bin/sh
if test -z "$1"

in=$(cat /dev/stdin)
ttytter -status="$in"

ttytter -status="$@"

which can be used in two ways:

command | twit


twit blah blah blah

I set up a private twitter account and use TTYter to push various information to it. Some information comes from and hourly cron and for others that run at unexpected times, I just added "| twit" to them.

I use LauncherPro on the phone and it comes with a twitter widget. Set to update every 30 minutes, I just look at the widget to get an update on pretty much anything I may be interested in.

Monday, November 1, 2010

Simple "to do list" voice script for Tasker/voice

I had to do something at work today which required me to examine several things to see if they needed done, do something to them, and mark them off my mental list of things that needed done.

This is something that nearly everyone does on a daily basis but there were just too many items on my todo list to remember them all so I took 10 minutes and whipped up this little script which I named "list".

#! /system/bin/sh
grep -E -i -q "add|delete" /sdcard/.voice || exec echo sorry
grep -E -i -q "^add|^delete" /sdcard/.voice && sed -i 's/^/list /' /sdcard/.voice

COMMAND=$(awk '{ print $2}' /sdcard/.voice)
ARG=$(cut -f3- -d ' ' < /sdcard/.voice)

if [ $COMMAND == "add" ]; then
echo $ARG >> /sdcard/list
echo "Added: $ARG"

elif [ $COMMAND == "delete" ]; then
sed -i "/$ARG/d" /sdcard/list
echo "Deleted: $ARG"

This simply adds or deletes things from a list based on whether it finds "add blah blah blah" or "delete blah blah blah" in the file at /sdcard/.voice.

I created a new task in Tasker with the following actions:

1- Variable set %LIST to EOF
2- Locale Execute Plugin: @ list
3- Wait 500ms
4- Read Paragraph /sdcard/list to var %LIST
5- Flash %LIST

I set this to trigger on the keyword "list**" with the Tasker voice command I've been talking about in the last few posts. The end result is this:

I say "list add go to work"

It flashes:
go to work

I say "list add pay bills"

It flashes:
go to work
pay bills

I say "list delete work"

It flashes:
pay bills

I say "list add go on vacation"
It flashes:
pay bills
go on vacation

I say "list delete bills"
It flashes:
go on vacation

I say "list add sleep late"
It flashes:
go on vacation
sleep late

I added a line in the script to make this loopable. The line I added will add "list" to the beginning if it's not there already and execute normally. If called by the normal voice task, you still have to say "list add/delete blah blah blah" because "list" is the trigger word, but when called in a loop, you can just say "add/delete blah blah blah" and the script will recognize it. This makes it possible to keep using the list while performing your duties.