由于需要有输入密码的地方需要,需要安装expect
sudoapt-get install expect
首先编写一个脚本, 例如 compile.cron
内容为
10 19 * * 5 /bin/bash /home/songhanqing/boot.sh > /home/songhanqing/log 2>&1
boot.sh为要执行的自动编译android版本的命令 /home/songhanqing/log 2>&1 保存编译log到 /home/songhanqing/log 文件
10 19 * * 5 每周的 星期5 19:10分开始编译。
之后可以用 命令
crontab compile.cron 如果不行可以 用 sudo crontab compile.cron
crontab -l 查看 任务
crontab -e 可以编辑和删除要执行的任务
需要用expect 执行的脚本的地方加上
expect << ! //开始
! //结束
看下边红色标记
在copy文件的时候,发现总不能完全执行完就结束了,
发现是由于,expect 默认timeout为30秒,
所以添加 set timeout -1 这样为无穷大就可以了
看下边紫色标记
----------------
1 #!/bin/bash
3 source ~/.bashrc
4 export JAVA_HOME=/home/songhanqing/tools/jdk1.6.0_31
7 export PATH=$JAVA_HOME/bin:$PATH
9 export PATH=$PATH:/usr/local/bin
10 export PATH=$PATH:/home/songhanqing/code/prebuilts/gcc/linux-x86/mips/mipsel-linux-android-4.7/bin
11 export PATH=$PATH:/home/songhanqing/bin
12
13 cd /home/songhanqing/soft_verison
14 rm -rf *
15 expect <<!
16 spawn repo init -u git://192.168.1.110/jzcode/m200_android4.3/manifest.git -m glass_p0.xml
17 expect "*[songhanqing]:*"
18 send "\r"
19
20 expect "*[songhanqing]*:"
21 send "\r"
22 send "y\r"
2 3 !
24 repo sync
25
26 source build/envsetup.sh
27 lunch magic-userdebug
28 cd bootable/bootloader/uboot
29 make coldwave_android_msc0
30 cd /home/songhanqing/soft_verison
31 cd ./kernel
48 spawn scp
32 make magic_lcos_android_defconfig
33 make zImage
34 cp arch/mips/boot/compressed/zImage ../device/ingenic/magic/kernel
35 cd ..
36 make bootimage
37 make update-api
38 make -j8
39 riqi=`date +%Y-%m-%d`
40 mkdir -p /home/songhanqing/$riqi
41
42 cp /home/songhanqing/soft_verison/bootable/bootloader/uboot/u-boot-with-spl-mbr-gpt.bin /home/songhanqing/$riqi
43 cp /home/songhanqing/soft_verison/out/target/product/magic/boot.img /home/songhanqing/$riqi
44 cp /home/songhanqing/soft_verison/out/target/product/magic/recovery.img /home/songhanqing/$riqi
45 cp /home/songhanqing/soft_verison/out/target/product/magic/system.img /home/songhanqing/$riqi
46 expect <<!
47 set timeout -1
48 spawn scp -r /home/songhanqing/$riqi supervisiontech@192.168.1.110:/home/ftp/jz_bin
49 expect "*assword:*"
50 send "vision\r"
51 expect 100%
52 expect eof
53 !