[Miscellaneous Android Development] leajian:
Greetings :D

Hello everyone, I made a script to help developers solve problems and you become a more helpful user.

What does it do? :eek:

It exports to sdcard :

dmesg

last_kmsg

wakelocks

kernel version

logcat (normal and long)

radio (aka modem log)

getprop (aka build.prop)

running processes

partition info

mount info

RAM info

interrupts

boot logs from kernels like : nAa, lupus

Total maximum possible logs are

14 files

.

What should I do? :cyclops:

Send files from the folder with the time-stamp you have just created or send the tar.gz'ed file to the corresponding developer to help him. Each time you run the script it creates a different folder with a unique time-stamp of the time and date you dumped the logs.

Send whatever is needed, everything is in bug_reporter folder.

Ok, how do we install this thing? :rolleyes:

Make sure you download the latest version [ v1.4 is the latest ] which is attached below and put it in your sdcard...and that your device is rooted.

Go to CWM recovery and flash it! It does no harm, it just copies a small 6kb file in your /system/xbin. So there is no need to uninstall it later. It will accompany you until you flash a new ROM.

If you are coming from another version, just flash it over.

If you are having any problems, first attach the debug.txt from bug_reporter folder and tell me your

device, kernel and ROM

. The problem might be your busybox installation though.

Ok, how do we use this thing? :rolleyes:

Make sure you have a terminal app, I use this : https://play.google.com/store/apps/details?id=jackpal.androidterm

Open a terminal app and just type :

su
bug

IT WON'T WORK PROPERLY IF NOT EXECUTED FROM /system/xbin/, SO IT MAY FAIL WITH SCRIPT MANAGER. TRY AND REPORT BACK TO ME.

That's it? :confused:

Yes. :good:

If you have any questions, feel free to ask anything. :highfive:

Any screenshots? :angel:

Yep. :o

I want to contribute/redistribute :cool:

Oh, please do! :victory: Spread it, mod it, rewrite it, make your own version, inform developers, tell ROM cookers to include it, do whatever you want with it, but please don't forget me...

Post any improvements or modifications for me here. :fingers-crossed:

Here is the "source code" of it:

#!/system/bin/sh
DIRECTORY="/sdcard/bug_reporter"

clear

#ROOT CHECK, FOR SCRIPT TO WORK ON ALL su VERSIONS
clear
echo "Checking root permissions..."
if [ "$(id)" != "uid=0(root) gid=0(root)" ];
then
echo " - Denied?"
echo " * Please accept superuser permission..."
echo " /!\ FIRST TYPE: su"
echo
exit
elif [ "$(id)" == "uid=0(root) gid=0(root)" ];
then
echo " - Granted! SU binary version : $(su -V)"
else
echo
echo " /!\ Some errors occured... Obviously..."
echo " * Run the script again."
echo " - Asking superuser permissions..."
echo " ( i ) If you see somewhere "root", we are OK,"
echo " else, we are NOT."
su
echo " Look at it :"
id
exit
fi

{
#CREATING THE NEST DIRECTORY
#
if [ ! -d "$DIRECTORY" ];
then
echo " - Directory not found.
echo " - Creating...
mkdir $DIRECTORY
echo " - Done!
else
echo " - Fatal error! Exiting...
exit
fi

#FOR DEBUGGING REASONS
#
echo " - SU binary version : $(su -V)"

#VACUUM
#
clear
##SETTING MAX MB
if [ ! -f $DIRECTORY/max_mb.txt ];
then
echo Logs can easily exceed over the size you can imagine.
echo So, I will ask you if you want me to delete them
echo in the future.
echo
echo "How many MB of logs do you want to keep?"
echo "(5 MB recommended)"
read keep

KEEP_KB=$(echo $(($keep*1024)) )
echo $KEEP_KB > $DIRECTORY/max_mb.txt
clear

fi

SIZE=$(du -s $DIRECTORY | cut -f1)
MAX_MB=$(cat $DIRECTORY/max_mb.txt)
MB=$(echo $(($SIZE/1024)) )

##CHECKING IF MAX MB ARE REACHED AND PROMPT
if [ "$SIZE" -ge "$MAX_MB" ];
then
echo Log files have reached the maximum size you have set.
echo Their size is around $MB MB.
echo
echo Do you want to clean all logs?
echo "(y = Yes, clean. n = No, reset max MB value)"
read clean
echo
if [ "$clean" == "y" ] || [ "$clean" == "Y" ] || [ "$clean" == "yes" ] || [ "$clean" == "YES" ];
then
rm -r $DIRECTORY
echo - Cleaned!
echo - Re-run the script to set again the max MB value.
echo - Bye!
exit
elif [ "$clean" == "n" ] || [ "$clean" == "N" ] || [ "$clean" == "no" ] || [ "$clean" == "NO" ];
then
rm $DIRECTORY/max_mb.txt
echo - Value reseted!
echo - Re-run the script to set again the max MB value.
echo - Continuing...
sleep 2
else
echo "/!\ Illegal character. Try again...";
sleep 1
exec bug
fi
fi

#PRECALCULATIONS FOR LOGCATING
#
ls dev/log > $DIRECTORY/devlog
MAIN=$(grep main $DIRECTORY/devlog)
RADIO=$(grep radio $DIRECTORY/devlog)

clear
DATETIME=$(date +%Y%m%d%H%M%S)
export DATETIME

echo " ,-------------, Everything is saved on sdcard"
echo " / leajian@xda / under bug_reporter folder."
echo "/_____________/__,------,"
echo "| Bug reporter v1.4 / Remember the timestamp!"
echo "|_______________,-----' Format : yyyymmddhhmmss"
echo
echo "It exports and compresses as tarball the following :"
echo "* dmesg"
echo "* last_kmsg"
echo "* wakelocks"
echo "* kernel version"
echo "* logcat (normal and long)"
echo "* radio (aka modem log)"
echo "* getprop (aka build.prop)"
echo "* running processes"
echo "* partition info"
echo "* mount info"
echo "* RAM info"
echo "* interrupts"
echo "* boot logs from kernels like : nAa, lupus"
echo

cd $DIRECTORY
#TIMESTAMP WHICH IS THE FOLDER'S NAME WHERE THE FILES ARE SAVED ON EACH RUN
echo - report timestamp : $DATETIME
mkdir "$DATETIME"
echo - exporting...

#FOR DMESG
echo - dmesg
dmesg > $DIRECTORY/"$DATETIME"/dmesg.txt
echo - OK!

#FOR LAST_KSMG
#
echo - last_kmsg
if [ -f /proc/last_kmsg ];
then
cat /proc/last_kmsg > $DIRECTORY/"$DATETIME"/last_kmsg.txt
echo - OK!
else
echo " /!\ last_kmsg not found!";
fi

#FOR WAKELOCKS
#
echo - wakelocks
if [ -f /proc/wakelocks ];
then
cat /proc/wakelocks > $DIRECTORY/"$DATETIME"/wakelocks.txt
echo - OK!
else
echo " /!\ wakelocks not found!";
fi

#FOR KERNEL VERSION
#
echo - kernel version
if [ -f /proc/version ];
then
cat /proc/version > $DIRECTORY/"$DATETIME"/kernel.txt
uname -a >> $DIRECTORY/"$DATETIME"/kernel.txt
echo - OK!
else
echo " /!\ version not found!";
fi

#FOR LOLCATS
#
if [ "$MAIN" != "main" ] || [ "$RADIO" != "radio" ];
then
echo " /!\ main and radio logging aborted!";
echo "* I can't logcat properly, loggers may be disabled."
echo "- Your ROM's dev must have disabled it via a script."
echo " OR"
echo "- Loggers are disabled from kernel."
else

##MAIN
echo - logcat
logcat -d > $DIRECTORY/"$DATETIME"/logcat.txt
echo - OK!
echo - long logcat
logcat -v long -d > $DIRECTORY/"$DATETIME"/long_logcat.txt
echo - OK!

##RADIO
echo - radio
logcat -b radio -v time -d > $DIRECTORY/"$DATETIME"/radio.txt
echo - OK!
fi

#FOR GETPROP
#
echo - getprop
getprop > $DIRECTORY/"$DATETIME"/getprop.txt
echo - OK!

#FOR RUNNING PROCESSES
#
echo - processes
ps > $DIRECTORY/"$DATETIME"/processes.txt
echo - OK!

#FOR PARTITION INFO
#
echo - partition info
df > $DIRECTORY/"$DATETIME"/partitions.txt
echo - OK!

#FOR MOUNTS
#
echo - mount info
mount > $DIRECTORY/"$DATETIME"/mounts.txt
echo - OK!

#FOR RAM
#
echo - RAM info
free > $DIRECTORY/"$DATETIME"/ram.txt
echo - OK!

#FOR INTERRUPTS
#
echo - interrupts
cat /proc/interrupts > $DIRECTORY/"$DATETIME"/interrupts.txt
echo - OK!

##----DEVIDER FOR SPECIAL LOGS----##

#BOOT LOG FOR nAa KERNELS AND DERIVATIVES
#
if [ -f "/boot.txt" ];
then
echo " ( i ) Oh, I found a boot log too!"
echo "- That's found on some nAa kernels, backing it up."
cat /boot.txt > $DIRECTORY/"$DATETIME"/boot.txt
echo - OK!
fi

#BOOT LOG FOR lupus KERNELS AND DERIVATIVES
#
if [ -f "/tmp/lupus.log" ];
then
echo " ( i ) Oh, I found a boot log too!"
echo "- That's found on some lupus kernels, backing it up."
cat /tmp/lupus.log > $DIRECTORY/"$DATETIME"/boot.txt
echo - OK!
fi

##----###----##

#CLEANING UP UNEEDED FILES FOR USER
#
echo - Cleaning up...
##CLEANING LAST TARBALL
rm *.tar.gz 2>&1 | >$DIRECTORY/devlog
##devlog IS A FILE OF PRECALCULATIONS FOR LOGCAT
if [ -f "$DIRECTORY/devlog" ];
then
rm $DIRECTORY/devlog
fi

#COMPRESSING FOR EASY SENDING
#
echo - Compressing logs...
echo - Done!
echo " ( i ) Send "$DATETIME".tar.gz to developer(s)!"
tar -zcf "$DATETIME".tar.gz "$DATETIME"

echo - Exiting...

#ADVERTISING THE SCRIPT
#
echo "http://xdaforums.com/showthread.php?p=41107818" > $DIRECTORY/"$DATETIME"/"I used bug_reporter script.txt"

#DEBUGING MY SCRIPT
#
} 2>&1 | tee $DIRECTORY/debug.txt
exit