Syntax error near unexpected token `('

detect_mouse_mvt.sh
/home/andy/bin/detect_mouse_mvt.sh: line 4: syntax error near unexpected token `('
/home/andy/bin/detect_mouse_mvt.sh: line 4: `fh = file('/dev/input/mice')'
#!/bin/bash
# 
# 
fh = file('/dev/input/mice')
while True:                 
    fh.read(3)
    print 'Mouse moved!'

I found this, but it only moves the mouse. Looking for something that detects mouse movement so I can perform some command.

xdotool mousemove_relative --sync 5 0
syntax error near unexpected token `('
`fh = file('/dev/input/mice')'

Should be `(`
Could that be part of the issue?

I am confused. :confused:

What do the red single quotes mean?

I do not know what to change in the fh statement.

Thanks.

To me this was the old sh syntax for executing what is contained in those single "left" quote, replaced by in early ksh (and later sh ) by $(to execute...) syntax, my 2 cents would be : because of the possible confusion between those single quotes making it a nightmare to debug when many the new syntax is clear and univoque...

Sure we're talking about a bash script in post #1, despite the bash shebang? In a bash script, a variable assignment can't have spaces around the = sign, so

fh = file('/dev/input/mice')

won't do that. What is the purpose of the parentheses following the *nix file command?

file '/dev/input/mice'
 /dev/input/mice: character special (13/63)

would yield a correct result, and can be assigned to a variable the way described above, called "command substitution".

The rest of the script isn't bash shell code either...

In my defense, I did not write the code.

python - How to detect mouse and keyboard inactivity in linux - Stack Overflow

I think it is part of a python script and not bash.

So, is there no fix?

I will continue researching if xdotool may be able to detect mouse movement.

JUST mouse movement, nothing else? How far would

read -n1 TMP </dev/input/mice

get you, given "mice" IS the mouse in question?

Please note that in your post #1 script having a bash "shebang" and python commands (without specifying or calling) the repsective interpreter is doomed to fail.

Hi drew77...

And it is Python 2.x.x too and would fail without mods on Python 3.x.x.

you could use: cat /dev/input/mice but I suspect it will produce lots of garbage unless you know how to decode what is presented during mouse movement.

EDIT:
This will not be portable so be well aware!

Bazza.

I did not know it was a python script until later.

I pasted the code into one of my blank bash scripts.

--- Post updated at 09:45 AM ---

read -n1 TMP </dev/input/mice
bash: /dev/input/mice: Permission denied

Would you care to have a crack at this?

#!/bin/bash
#
#

xidle -delay 5 -sw -program "/home/andy/bin/test.sh" -timeout 5
exit 0

What can I do when a script hangs?

Ctrl C does not work. Is closing the terminal the only option?

Then it looks as though your Linux flavour requires '/' - root access.
So you will have to use 'read' as root user.

Also I know that there is binary inside the garbage so you might have to add the '-r' flag, read -r -n1 TMP </dev/input/mice to accept raw data.

1 Like

Then it looks as though your Linux flavour requires '/' - root access.

I used

sudo read -n1 TMP </dev/input/mice
bash: /dev/input/mice: Permission denied

OK.

Are you an admin user of said computer, or standard with no admin access?
If so switch to an admin user and run from direct root.

Also give us the results of:

ls -l /dev/input

And:

cd /dev/input
ls -l

Ensure '/dev' directory is at least r-x and the 'input' directory is also at least 'r-x'; (you are reading a device so 'w' is not needed) using:

ls -l /
cd /dev
ls -l

Not quite clear? I am the only user of my computer.

ls  -l /dev/input 
total 0
drwxr-xr-x 2 root root     100 Mar 22 15:40 by-id
drwxr-xr-x 2 root root     120 Mar 22 15:40 by-path
crw-rw---- 1 root input 13, 64 Mar 22 15:40 event0
crw-rw---- 1 root input 13, 65 Mar 22 15:40 event1
crw-rw---- 1 root input 13, 74 Mar 22 15:40 event10
crw-rw---- 1 root input 13, 75 Mar 22 15:40 event11
crw-rw---- 1 root input 13, 66 Mar 22 15:40 event2
crw-rw---- 1 root input 13, 67 Mar 22 15:40 event3
crw-rw---- 1 root input 13, 68 Mar 22 15:40 event4
crw-rw---- 1 root input 13, 69 Mar 22 15:40 event5
crw-rw---- 1 root input 13, 70 Mar 22 15:40 event6
crw-rw---- 1 root input 13, 71 Mar 22 15:40 event7
crw-rw---- 1 root input 13, 72 Mar 22 15:40 event8
crw-rw---- 1 root input 13, 73 Mar 22 15:40 event9
crw-rw---- 1 root input 13, 63 Mar 22 15:40 mice
crw-rw---- 1 root input 13, 32 Mar 22 15:40 mouse0

ls -l
total 0
drwxr-xr-x 2 root root     100 Mar 22 15:40 by-id
drwxr-xr-x 2 root root     120 Mar 22 15:40 by-path
crw-rw---- 1 root input 13, 64 Mar 22 15:40 event0
crw-rw---- 1 root input 13, 65 Mar 22 15:40 event1
crw-rw---- 1 root input 13, 74 Mar 22 15:40 event10
crw-rw---- 1 root input 13, 75 Mar 22 15:40 event11
crw-rw---- 1 root input 13, 66 Mar 22 15:40 event2
crw-rw---- 1 root input 13, 67 Mar 22 15:40 event3
crw-rw---- 1 root input 13, 68 Mar 22 15:40 event4
crw-rw---- 1 root input 13, 69 Mar 22 15:40 event5
crw-rw---- 1 root input 13, 70 Mar 22 15:40 event6
crw-rw---- 1 root input 13, 71 Mar 22 15:40 event7
crw-rw---- 1 root input 13, 72 Mar 22 15:40 event8
crw-rw---- 1 root input 13, 73 Mar 22 15:40 event9
crw-rw---- 1 root input 13, 63 Mar 22 15:40 mice
crw-rw---- 1 root input 13, 32 Mar 22 15:40 mouse0

Looks like both are at least rx.

drwxr-xr-x 4 root root 360 Mar 22 15:40 input

drwxr-xr-x 21 root root 4600 Mar 22 15:40 dev

--- Post updated at 04:17 PM ---

andy@7_~$ su
Password:
su: Authentication failure

--- Post updated at 04:22 PM ---

My script works if I use sudo -i

Can I run the script without having to input the password?

OK.

From an actual root user go to the '/dev/input' drawer and:
cat < mouse0
AND:
cat < mice
...and in each see if mouse movement presents garbage on the terminal window.
Ctrl-C should quit the test(s).

The redirection is implicit normally but I have known when attacking the HW normal rules sometimes do not apply so one has to be explicit.

One of the 'events' does the same but it was ages ago and I can't remember which one it is.

--- Post updated at 09:48 PM ---

Hi drew77...

I am pretty sure on a personal system you need root access to mess with HW devices.
But this was 10+ years ago when I hammered the HW via its device structure on a Linux tool.

Do you not have root access at all as an admin?

Not sure what you mean here?

<Do you not have root access at all as an admin?

No garbage when running the 2 commands.

Hi drew77...

I have run Linux Mint 19 up on my MacBook Pro to get to the devices.
All from memory from years ago, I am surprised they still work.

As I have previously said to access a HW device you have to run as root.
I also said one of the events do it.
And also I have said it passes binary garbage.

I have sent a screen shot showing MY 'event7' the EXTERNAL mouse and 'event14' the trackpad.

These events are multiplexed mouse and trackpad events and show ANYTHING that either does.

Yours may not be the same event numbers but try mine first and then go through them one by one. As you are reading them and NOT attempting to write then it is relatively safe to do so.

EDIT:
By root access I mean open up a root terminal, set up as such, directly from an admin account?
ISTR that many years ago one could, but of that I am probably wrong these days.