Crontab Setup for Note II (Needs Root) - Galaxy Note II Android Development

This is a tutorial for setting up crontab on Samsung Galaxy Note II. This is intended for native unix users to be able to use cron on their phones for scheduling various tasks such as reminders, backups, scheduled reboots, wifi on-off, etc.
Installation Instructions:
What you need:
Rooted Galaxy Note II with latest busybox installed
Ability to run scripts at startup [not required if you are willing to manually start crond every time you reboot.]
Step 1: Create a directory /data/root, and create a text file name root inside it. Your cron entries should go inside /data/root/root.
Step 2: Download the attached crontab.sh and place it in your mobile phone. You need to execute this script on startup. So if you have /etc/init.d folder, please it there. If you dont, you should contact your dev to check if your rom supports executing user scripts on startup.
Step 3: Understanding the (attached) script.
Any unix program including crontab references a users details from the /etc/passwd file. So we create a passwd file with root user's credentials. (Android does not have this by default).
Crontab is a compiled binary that looks for sh shell in the directory /bin/sh - a standard for unix. Unfortunately bin directory is inside /system in our phones, so we symlink it.
Set Timezone. TZ variable is sources by crontab to know the local timezone. Please modify the script to set it according to your location.
And finally, crond -c /data/root will start cron daemon on your phone sourcing crontab files from /data/root directory.
Step 4: Write your crontab file (Below is a typical crontab file). Please visit this link for an awesome tutorial on crontab.
Code:
[B][email protected]:/data/root # cat /data/root/root[/B]
# Script to make sure crontab is running
* * * * * echo "Crontab last ran on `date`" >> /storage/sdcard0/.crontab
# Script to backup whatsapp databases at 5 am everyday.
0 5 * * * cp /data/data/com.whatsapp/databases/* /storage/extSdCard/backups/whatsapp/
### FREQUENTLY ASKED QUESTIONS ###
How to make sure it is working
In terminal - type pgrep -l crond (lower case L). If it return a process id and command name, crontab is running. If you see more than one "crond" running, it is likely that executed your script twice. kill the other script using command kill -9 <process id>
[*]My tasks are executing twice
Please re-read FAQ #1.
[*]It stopped working after i rebooted my phone.
You are probably not executing this script on startup. Reread this thread properly again.

kkoolpatz said:
This is a tutorial for setting up crontab on Samsung Galaxy Note II. This is intended for native unix users to be able to use cron on their phones for scheduling various tasks such as reminders, backups, scheduled reboots, wifi on-off, etc.
Installation Instructions:
What you need:
Rooted Galaxy Note II with latest busybox installed
Ability to run scripts at startup [not required if you are willing to manually start crond every time you reboot.]
Step 1: Create a directory /data/root, and create a text file name root inside it. Your cron entries should go inside /data/root/root.
Step 2: Download the attached crontab.sh and place it in your mobile phone. You need to execute this script on startup. So if you have /etc/init.d folder, please it there. If you dont, you should contact your dev to check if your rom supports executing user scripts on startup.
Step 3: Understanding the (attached) script.
Any unix program including crontab references a users details from the /etc/passwd file. So we create a passwd file with root user's credentials. (Android does not have this by default).
Crontab is a compiled binary that looks for sh shell in the directory /bin/sh - a standard for unix. Unfortunately bin directory is inside /system in our phones, so we symlink it.
Set Timezone. TZ variable is sources by crontab to know the local timezone. Please modify the script to set it according to your location.
And finally, crond -c /data/root will start cron daemon on your phone sourcing crontab files from /data/root directory.
Step 4: Write your crontab file (Below is a typical crontab file). Please visit this link for an awesome tutorial on crontab.
Code:
[B][email protected]:/data/root # cat /data/root/root[/B]
# Script to make sure crontab is running
* * * * * echo "Crontab last ran on `date`" >> /storage/sdcard0/.crontab
# Script to backup whatsapp databases at 5 am everyday.
0 5 * * * cp /data/data/com.whatsapp/databases/* /storage/extSdCard/backups/whatsapp/
### FREQUENTLY ASKED QUESTIONS ###
How to make sure it is working
In terminal - type pgrep -l crond (lower case L). If it return a process id and command name, crontab is running. If you see more than one "crond" running, it is likely that executed your script twice. kill the other script using command kill -9 <process id>
[*]My tasks are executing twice
Please re-read FAQ #1.
[*]It stopped working after i rebooted my phone.
You are probably not executing this script on startup. Reread this thread properly again.
Click to expand...
Click to collapse
Interresting indeed,
Will digg this based on your informations, thank you

thx, can confirm it`s working on cm7.

Related

[GUIDE] SManager - How to use Commands

Hi,
I want to learn some of the commands for use in SManager (Script Manager) for ANDROID.
https://sites.google.com/site/devwom/script-manager
Does anyone know a suitable thread with guide or commands for SManager? I tried searching the web and XDA but did not find anything myself.
Specifically I want to know the cmd line to start an app.
EDIT 1:
Spent a good few hours trying to google a solution but drawn a blank.......Maybe Shell Scripts for Linux are not same as for Android...?
I would like to be able to run a script that does the following:
Checks if a directory exists on the sdcard
then executes a command (renaming of 2 directories)
then starts a program
EDIT 2:
well a few emails with the author of SManager and I was able to write my first script to check if the app is running and then if not, to rename folders and start the other version of the app. (I have Navigon Europe as well as Navigon Australia and was looking for a solution to allow both to co exist on my One-X at the same time. As both apps share the same directory structure the issue was that starting one version would overwrite the critical files of the other).
Now with my script installed as a widget I can toggle between each version without problem.
Here is some useful information on shell language for others (credits to the author of SManager Devwom):
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
Here are some critical bits of info received during my emails with him:
Thanks a lot for your interest in SManager.
The requested commands is a mix between linux commands and android os commands.
To get info about each command you can search in google and select the preferred page.
But the commands available in each Android device depends on running rom.
To get all available commands in your device, simply execute a ls (lower case LS) in system directories, that is:
ls /system/bin
ls /system/sbin
ls /system/xbin
ls /system/usr/bin
ls /system/usr/sbin
ls /system/usr/xbin
These are the most common directories where binaries resides in android devices.
May be you also can have commands at:
ls /bin
ls /sbin
ls /usr/bin
ls /usr/sbin
usually android rooted roms have the well known busybox, to get a list all comands inside it simply execute
busybox
to get all installed packages (and running names) from your device you can execute:
pm list packages
to get info about running process
ps
or
ps aux
or
ps -aux
depending on ps version installed
If conditions are based on test bash command this command is a bit confused, because usually it is named as [, and other times it is built-in inside shell
read "test man page" to get a full list of test command flags.
To check if an app is running:
if [ -n "$(ps|grep os.tools.scriptmanager)" ] ; then
echo SManager is running
fi
To check if app is NOT running:
if [ -z "$(ps|grep os.tools.scriptmanager)" ] ; then
echo SManager is NOT running
fi
To check if a file exist:
if [ -e /sdcard/file ] ; then
echo /sdcard/file exists
fi
To check if a file exist and it is a directory:
if [ -d /sdcard/file ] ; then
echo /sdcard/file exists and is directory
fi
To rename a directory simply use mv command:
I hope you can build your script with this info.
Start app it is very easy but getting correct info to start app is a bit confused.
starting app uses "am command"
To get correct info to start app you should execute:
logcat |grep Starting
in a terminal on device
then go to launcher and launch desired app
then go back to the terminal and you will see a line with info about how to fill am command.
For example if you execute SManager
in
logcat|grep Starting
output you will see
I/ActivityManager(* 275): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=os.tools.scriptmanager/.launcherActivity } from pid 377
so to start scriptmanager you need the following command
am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n os.tools.scriptmanager/.launcherActivity
I do not know how to stop apps from command line, I usually use killall command:
killall os.tools.scriptmanager
if you do not have killall command you can use grep and awk or cut commands
kill "$(ps|grep os.tools.scriptmanager|grep -v grep|awk '{print $2;}')"
or
kill "$(ps|grep os.tools.scriptmanager|grep -v grep|cut -f5 -d" ")"
may you need adjust -f5 flag
To execute script as shortcut install SMWidgets.
Scripts usually ends with last line , ie, not special action is required, it will exit with the last executed command return code
Also you can add
exit 0
or preferred exit value, but 0 usually means OK
To end script in the middle use
exit value
where value usually it is not 0
Also it is better use mv command instead rename command.
rename command it is not linux standard, but mv command is in all linux shells.
Android shell programing it is not equals to linux shell programming but this was one of my first scripting documents many years ago and it can be used as a guide. http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
Best regards,
Devwom
Thanks, this is valuable information! It's a shame this thread didn't get more replies
I've been looking to change my wallpaper by script, but so far I haven't been succesful. With your guide, I guess I'm a step closer to my goals!
Hi.
Perhaps developer of smanager or any expert is reading...
I would like to write a script for 2 purposes. Both handle with samba share running on my ubuntu.
1st situation.: I would like to move my media, download and documents files from android to the desired folder on my Ubuntu, which is shared by samba in my LAN.
The goal is to start this script with just touching a widget.
2nd situation: I would like to copy files from my samba shared folder in ubuntu to a specific folder on sdcard in android. All files in folder on sdcard should be deleted before copying. Again just by touching a widget.
Shared folder on samba are with password and rw.
Till now I am doing it manually with esexplorer...
I would like to do it with script.
Sent from my Incredible S using xda app-developers app

[Tut] Fast Change Kernel Paramteres

This is a very simple guide for build a script that manipulates the kernel parameters. Using SManager we will add it on us home or dock.
No specific skills are required, only patient.
What You Need:
- Root Permissions
- a customizable kernel
- SManager & SMWidgets
- Busybox
------------------------------------------------
1) First make your personal script for manipulating the kernel parameters.
Make a new file without extension on your computer and open it with a text editor
a) write this two line (IMPORTANT !!!)
#!/system/bin/sh
busybox mount -o remount,rw /system
the first line is the standard initialization of a sh script in Linux-Unix system. The second line allows the writing of the file system.
b) Now add the code. All the kernel parameters are text file located in the /sys/ folder. Is possible to edit such parameters writing
echo NEWVALUE > / PATH / OF / THE / DESTINATION / PARAMETER
for example, for changing the minimum frequency
# CPU Min Freq
echo 700000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
In sh scripts the line with # symbol won't be execute, so you can write whatever you wants.
c) The most important parameters are located in:
# CPU Min Freq
/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
# CPU Max Freq
/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
# CPU Governor
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# IO Scheduler (ALL THIS PARAMETERS MUST BE CHANGED FOR THE SCHEDULER)
/sys/block/mmcblk0/queue/scheduler
/sys/block/mmcblk0boot0/queue/scheduler
/sys/block/mmcblk0boot1/queue/scheduler
/sys/block/mtdblock0/queue/scheduler
I attached a simple script in this form here. You can found other parameters here, or A complete documentation of a kernel linux here. Other scripts and information about the Android kernel can be found here, here. A complete documentation of a kernel linux is here
BE CAREFUL WITH EDITING KERNEL PARAMETERS. ALWAYS READ THE DOCUMENTATION OF YOUR KERNEL AND CHECK THE PARAMETERS
d) Add this line at the end of the file for remount the system folder as read-able only
busybox mount -o remount,ro /system
now your script is done.
You can check and control the parameters by typing on the terminal or via ADB
cat / PATH / OF / THE / PARAMETER / YOU / ARE / CHECKING
------------------------------------------------
2) push the file on your phone. Set executable permission of file with an explorer or with chmod comand. Now open SManager, navigate to the path of the script and add it on its database. You can check it and test if everything works fine.
------------------------------------------------
3) the last step consists to add the shortcut of the script your home. With the most advanced launcher you can change the icon and the name and personalize it.
------------------------------------------------
4) optional: after the execution of the script with SWmanager the terminal will be open. To automatically return on the home you must add at the end of the script a line with the activity of your launcher related to the home button (this is a method I found, if someone has a better idea please tell me )
For Nova Launcher the code is:
am start -a android.intent.action.MAIN -n com.teslacoilsw.launcher/com.android.launcher2.Launcher
The method is used to found this activity was:
a) Open an app, and then return the to the home by pusching the central button
b) With the terminal emulator, or via adb, launch the logcat command
c) look for the last activity related to your launcher
d) replace the part after the -n with the string you have found
------------------------------------------------
All is done, if you have questions or some advice please contact me.
...The english will improve during my android experience :angel:

[Enable Cron for Android Phones]

# What is Cron ?
Cron is the time-based job scheduler in Unix-like computer operating systems. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates.
Examples :
The following line specifies that the amazing V6 Supercharger flush script execute every 3 hours of every day of the month, of every day of the week :
0 */3 * * * /system/xbin/flush
The following line causes the user program /data/jitter.sh to be run at 1am, 6pm and 11pm :
0 1,18,23 * * * /data/jitter.sh
# What is this thread about ?
This thread created just to share my little knowledge to activate crond in android phones, which could be usefull as additional tweak for our android phones.
# Disclaimer
Do this at your own risk - Ensure you understand that you are assuming all risks and there may also be other adverse effects. If you do not want to bear the risk, Please don't continue.
# Tested Device
- Galaxy Wonder GT-I8150 Stock ROM GB 2.3.6
- Lenovo S880 Stock ROM ICS 4.0.3
- Lenovo A560 Stock ROM ICS 4.0.3
# Requirement
1. Device is rooted, search Here howto root.
2. Already enable init.d, read Here howto enable init.d.
# Howto Install
1. Download SP8-CRON_v2.zip
2. Extract the Zip file to your SD card ( Install.sh & SP8CRON), for example in /mnt/sdcard.
*** Installation Method ***
Using ADB :
1. Connect to phone using adb, then run su.
2. go to extraction directory, example cd /mnt/sdcard
3. run this command : sh Install.sh
4. Installation script will begin and automatically reboot your phone when finish.
Using Script Manager :
1. Install Script manager.
2. Run Script manager, choose "Browse as Root".
3. Go to extraction directory, tap : Install.sh file , then tap : enable su (skull icon).
4. Installation script will begin and automatically reboot your phone when finish.
# Howto IUse
To modify cron schedule to meet your needs, please modify cron file at : /data/cronjob/root
(Examples above)
To check whether crond is running or not :
from ADB or Script Manager Console :
1. Run : su
2. Run :
pgrep -l crond , System will respon with showing pid number.
... and ...
crontab -l , System will list cron schedule list.
Thanks for reading this simple thread, Please hit Thanks if you found this thread is usefull
Changes :
V1 - Script on data folder and add logs.
V2 - Modify script to run on system folder, add Amazing V6 Supercharger flush and sclean script to schedule
-[spikecursed]-
Code:
# Mounting root
busybox mount -o remount,rw rootfs / 2>/dev/null;
ln -s /system/bin/ /bin 2>/dev/null;
mkdir -p /var/spool/cron/crontabs 2>/dev/null;
ln -s /system/etc/cron.d/root /var/spool/cron/crontabs/root 2>/dev/null;
busybox mount -o remount,ro rootfs / 2>/dev/null;
This is messing up my "internal sd card" so I am trying to set the path in the cron file instead but PATH=/system/bin isn't doing it, anyone know how to achieve this?
I have used the script and it's work great! Thank you very much.
I am writing this for any person having same problem as me.
I was struggle finding the real path for cron script.
The command crontab -e leads me to the incorrect path, the real and origin is at "/system/etc/cron.d/root".
We have to mount /system first with "mount -o remount,rw /system".
Then edit "/system/etc/cron.d/root" for cron script.
Don't forget to mount back /system as read-only with "mount -o remount,rw /system".

Setup cron in Android

Reqiurements
1. Root access (to run commands with ROOT privs. crond can still run using normal user privs.)
2. Busybox : for 'crond' service
3. init.d : to start 'crond' service at boot (It can also started manually)
4. Any Terminal Emulator on the device: To test cronjob without rebooting
Creating cronjob
Create the cronjob file in any accessible directory, say /sdcard/android/crontabs with filename root.
Write your cronjob inside the file root
Test without rebooting
Open any terminal emulator in device and run the following commands..
# su -
# crond -b -c /sdcard/android/crontabs
Now the crond service will start, to verify run...
# pgrep -l crond
or
# ps | grep crond
Autostart crond service at boot (need init.d support)
create a file at /system/etc/init.d with executable permission and enter the following lines
crond -b -c /sdcard/android/crontabs
Example cronjobs
* 2 * * * reboot
Will reboot your device at 2:00 AM eveyday
0 * * * * iptables -F
Will flush iptables rules every hour.
Notes
1. If you modify crontab, remember to restart crond daemon after killing the existing one.
2: Sometimes, the crond may not relay on Android timezone, it may use UTC instead.
can i use cron commands from other linux bases to work on android?
boyheadkick said:
can i use cron commands from other linux bases to work on android?
Click to expand...
Click to collapse
Yes, but the command inside the cronjob must be supported by your device. You can test the command support using a Terminal Emulator on device. The cronjob has the global format on all bases.

[HOW-TO] Fix when the phone stuck in boot splash after apply V6 Supercharger

You may have applied V6 Supercharger to your phone. And after reboot, you stuck at the boot splash. Reboot once and V6 Supercharger install script tell you that you aren't supercharged. Here is how to fix it. (If you get looped in boot animation, this is NOT your fix. Sorry!)
Depend on your rom, you may have to do one of following:
Open the (rooted) File Manager, open the directory /etc/init.d/ and open file 99SuperCharger. OR
Turn on ADB on your phone, use your computer to pull the file /etc/init.d/99Supercharger by running
Code:
adb pull /etc/init.d/99SuperCharger
Edit the file at the almost bottom of the file, change the following code:
Code:
if [ "`ps | grep -m 1 [a]ndroid`" ]; then HellzYeah;
else HellzYeah &; fi;
To look like this:
Code:
if [ "`ps | grep -m 1 [a]ndroid`" ] || [ $1 = "bypass" ]; then HellzYeah;
else
rm $bootloopcookie
$0 bypass &
fi;
Depend on what you have done on step 1, do the following:
If you use (root) file manager, save the file. Grant the superuser permission if needed. Then browse to /data and delete file !!SuperChargerBootLoopMessage.log. Don't worry if it's not exist.
If you use your computer to edit your file, run the following command:
Code:
adb root
adb remount
abd push /path/of/99SuperCharger /etc/init.d/99SuperCharger
adb shell
And inside the adb shell, run:
Code:
chmod 755 /etc/init.d/99SuperCharger
rm /data/!!SuperChargerBootLoopMessage.log
exit
Don't worry if file /data/!!SuperChargerBootLoopMessage.log doesn't exist.
And that's it! The V6 Supercharger bootscript is worked as it's designed to. Thanks to zeppelinrox to make this great script.
For one who want to know some technical info (and my assumption of the cause), wait me until tomorow and i'll explain how i found it. read on:
In order to run script in /etc/init.d at boot, the line like this is inserted in init.rc:
Code:
on boot
...
# Start the init.d service
exec /system/bin/sysinit
(In case of cm - for example)
But, what does the /system/bin/sysinit do? Just this:
Code:
#!/system/bin/sh
export PATH=/sbin:/system/sbin:/system/bin:/system/xbin
/system/bin/logwrapper /system/xbin/run-parts /system/etc/init.d
And this is the real source of problem. For some reason run-parts with logwrapper doesn't move on when you run a shell script function in background. If you scroll up in file 99SuperCharger, you'll found that "HellzYeah" is actually a function. And when it's execute in a boot process, "HellzYeah" will wait for boot process to continue. But run-parts (and the whole boot process) is waiting for the script to finish. You see? A deadlock!
The workaround is to execute function in the other way. What my modification do is re-executing the script with the parameter "bypass" in the background. This way, run-parts will not wait for it anymore. Then, when the script is re-executed, it will detect that it's called with the parameter "bypass". It'll run the function "HellzYeah", wait for boot process to finish, and, when the boot process is finished, supercharge your phone!
(if anyone is reading this, please inform zeppelinrox about this problem. I'm not able to post on the development forum yet.)
(This is my first post in xda. Hopefully it's helpful)

Categories

Resources