Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

termux-job-scheduler not running jobs #78

Closed
heywoodlh opened this issue Aug 11, 2019 · 4 comments
Closed

termux-job-scheduler not running jobs #78

heywoodlh opened this issue Aug 11, 2019 · 4 comments

Comments

@heywoodlh
Copy link

Trying to run a script with the job-scheduler and it doesn't seem to run every 15 minutes (despite it showing up in termux-job-scheduler --pending).

Aside from installing the termux-api package, is there something I need to do to ensure the job is runs?

Here is my command to schedule the job:

$ termux-job-scheduler --period-ms 900000 --script /data/data/com.termux/files/home/scripts/check-shell.sh --network any

Scheduling Job 0: /data/data/com.termux/files/home/scripts/check-shell.sh       (periodic: 900000ms) (battery not low) (network: NetworkRequest [ NONE id=0, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&VALIDATED Unwanted:  Uid: 10121] ]) - response 1

Here is the pending job:

$ termux-job-scheduler --pending

Pending Job 0: /data/data/com.termux/files/home/scripts/check-shell.sh  (periodic: 900000ms) (battery not low) (network: NetworkRequest [ NONE id=0, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&VALIDATED Unwanted:  Uid: 10121] ])

Again, is there some other step I am missing to ensure that my job runs?

@xalexalex
Copy link
Contributor

What's inside ~/scripts/check-shell.sh ?
Also, since termux-api v0.34 you don't need to explicitly state --network any because it is the default.

@heywoodlh
Copy link
Author

It's a script to check if an SSH process is running and if it isn't it runs another script to re-establish the tunnel (this isn't my most elegant script):

$ cat scripts/check-shell.sh
#!/usr/bin/env bash

ps aux | grep ssh | grep skynet | grep -q boomerang

STATUS="$?"

DATE="$(date +%m-%d_%H:%M)"

echo "reverse shell last checked: $DATE" > ~/log/shell-check.txt
if [[ "$STATUS" != 0 ]]
then
        echo "reverse shell not running, restarting."
        pkill sshd; sshd -E ~/log/ssh.log
        ~/.termux/boot/reverse-ssh.sh
else
        echo "reverse shell is running, exiting"
fi

As a hack-ey control, you can see that I have it echo the time that the script is run to ~/log/shell-check.txt and it never updates unless I run the script manually.

I did have a thought, maybe Termux's job scheduler handles STDOUT differently so that the echo command isn't ever redirected to the file? I would guess not because the SSH connection never gets re-established, but just a guess.

@xalexalex
Copy link
Contributor

Run termux-fix-shebang ~/scripts/check-shell.sh and retry. It should work (just tested and it worked for me).

@heywoodlh
Copy link
Author

That seems to have fixed it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants