我确实需要你对我目前的问题的建议。我正在尝试使用 netcat 转储 Android 上的整个分区。我已经为自动化过程创建了 4 个 bash 脚本。因此,我只需要执行 RunThis1.sh,它实际上执行 script1.sh、script2.sh 和 script3.sh。我使用 screen 运行这 3 个脚本,以便在 3 个不同的终端中运行。这 3 个脚本应该连续运行,因此这 3 个脚本之间应该有一个时间间隔。问题是,我不知道为什么问题仍然存在,输出不一致。起初,我成功地从中获取了 dd 图像。但目前,它失败了。我得到的要么是零大小的文件,要么是文本文件。而不是 dd 图像。
这是运行此1.sh:
#!/bin/bash
function GetPartitionName () {
#init number of line
sum=0
PartNameArray=""
while IFS=$' ' read -r column1 column2 column3 column4 ; do
temp=${column4}
if [ -n $temp ];
then
PartNameArray[$sum]=$temp;
sum=$((sum+1));
fi
done < ProcPart.txt
sum=$((sum-1));
}
#set working folder path, change to machine's specific path
path="/home/android/Work/"
#set partition list source file name
partList="ProcPart.txt"
#Lock files to maintain sequences
lock1=$path"file1.lock"
lock2=$path"file2.lock"
lock3=$path"file3.lock"
#initialize no of partition
sum=0
i=1
#Starting port, the next port is increment by 2
PortStart=8888
#initialize files and folder
find $path -name 'screenlog*' -delete
find $path"partitions/" -name '*' -delete
mkdir -p $path/partitions || exit 1
#run the get partition name function
if (test -f "$partList") then GetPartitionName
else
echo "Partition list file $partList not found!"
echo "script aborted."
exit
fi
#start iteration
for (( c=0; c<"$sum"; c++ ))
do
touch "$lock1"; screen -d -m -L -S "Screen PID for script #1" ./script1.sh "$PortStart";rm -f "$lock1";
echo "==========================================================="
echo "Establish forward socket connection at tcp port# $PortStart"
echo ". <done>"
if !(test -f "$lock1"); then
DevBlockPath="/dev/block/${PartNameArray[$c]}"
echo "Open Remote Shell and send $DevBlockPath to NC Server at port# $PortStart"
echo "Processing partition no $i out of $sum"
touch "$lock2"; screen -d -m -L -S "Screen PID for script #2" ./script2.sh "$PortStart $DevBlockPath";
echo "."
echo ".. <done>"
fi
if (test -f "$lock2") then
sleep 5
FileName=$path"partitions/${PartNameArray[$c]}.dd"
echo "Transfer data from Remote NC server port# $PortStart to localfile $FileName"
rm -f "$lock2"; touch "$lock3"; screen -d -m -L -S "Screen PID for script #3" ./script3.sh "$PortStart $FileName"; rm -f "$lock3";
echo "."
echo ".."
echo "... <done>"
fi
i=$((i+1));
PortStart=$((PortStart+2));
done
echo ===========================================================
Script1.sh:
#!/bin/bash
# first script
function script1 {
echo script1 port=$1
adb forward tcp:"$1" tcp:"$1"
}
script1 $1
Script2.sh:
#!/bin/bash
# second script
function script2 {
echo path=$2
strcommand="dd if=$2 | /dev/examiner/nc -l -p $1"
echo command=$strcommand
adb shell "$strcommand"
}
script2 $1 $2
Script3.sh:
#!/bin/bash
# third script
function script3 {
echo port=$1
echo filename=$2
#dump random words from openned NC ports to mtdbackup.dd
nc 127.0.0.1 $1 > "$2";
echo " dump randomFile $2 from NC has completed";
exit;
}
function quit {
exit
}
我们非常欢迎任何建议和意见,并将不胜感激。
干杯
答案1
你把事情搞得太复杂了。此代码设置为运行三个命令同时,你必须使用锁之类的东西来强制它运行连续screen
。我认为你这里根本不需要。
尝试screen
用它们调用的命令替换命令。也就是说,替换
screen -d -m -L -S "Screen PID for script #1" ./script1.sh "$PortStart"
和
./script1.sh "$PortStart"
然后删除所有锁定命令。您应该最终按顺序运行这三个脚本。