Here's a couple of scripts which can be used to help you resume where you left off, if for some reason Konq crashes, or the computer (such as loss of power, which is more frequent than I like where I currently live at).....
I use Konqueror more than any other browser, and tend to have many tabs opened up at the same time when researching for a project I happen to be working on.......It's quite frustrating when all of a sudden a crash occurs..........I do use Firefox at times (actually
Swiftfox), but more for troublesome sites that complain because I'm not using a "popular" browser, or for online transactions such as shopping or bill paying....
A little background info on how KDE and Konq work - It's true Konqueror has an automatic session recovery of sorts already, but the problem is it recovers a previously SAVED session which is restored when first logging in to KDE.........NOT the session you were working on at the time of the crash......
So I came up with these little scripts to make my life a bit easier, and anyone else's, by using the 'kfmclient' command line syntax to restore the URLs found in the crash log....This crash log is a temporary running log file that is written to at the time a tab is opened or closed (on-the-fly), when a new browser window is opened up........When the browser window is finally closed, the log file is deleted automatically to avoid cluttering up the user's temp directory......Therefore, if a crash occurs, the log file never gets deleted........
The first script (log2url) mines the active URLs found in the crash log, ignoring any tabs that were closed by the user during the course of the session, and builds a list of URLs.....This list has the same name as the crash log, but replaces the ".log" extension with a ".urls" extension, and drops it in the user's $KDEHOME directory ($HOME/.kde)......I also use this to not only recover from crashes, but as a way to save sessions for a particular project I'm working on.......I'm a command line freak, so I'm more comfortable saving sessions this way than saving them as Konqueror "profiles".....
The second script (konqrestore) opens up a new browser window and populates it with opened tabs using the URLs from the list generated by the first script........This script can be used directly on crash logs, as well as the saved URL lists..........For the crash logs, it merely calls on the first script to convert the log into a URL list, then uses the newly saved list to restore a session, which also means 'konqrestore' depends on 'log2url' when working with log files........
Both scripts will accept "file://" paths, which means you can right-click on the desired file in the Konq filemanager and choose "Copy", then pasting either in the "Run Command" dialog box, or a Konsole window.........The argument is optional, meaning they will find the most recent files in the default places if no file was specified as an argument - log2url will look in the user's KDE temp directory, which is '/tmp/kde-$USER', for the latest crash log; konqrestore will look in '$HOME/.kde' for the latest URL list.......
Caveat emptor: It's best if there are no other Konqueror windows open in the current desktop (Desktop 1, for example), including the Konqueror filemanager...........What can happen is a new browser windows opens up with the first URL in the list, but then the rest of the URLs are opened up as tabs in the other Konqueror window.....This only applies to the windows open in the same desktop, not opened ones in the other desktops (2, 3, 4, etc).........This behavior doesn't always happen, but it does more often than not.......
Anyway, I hope you KDE fans find them as useful as I do.....
log2urlCode:
#! /bin/bash
################################################################################
##
## log2url: Converts KDE Konqueror crash logs to a list of URLs
##
## Usage: log2url [logfile]
## 'logfile' is an optional argument
##
## Written by CTWaley - Sep 2006.
##
## Freely given to the public domain by the author
##
################################################################################
readonly PROG="${0##*/}"
KDEHOME="${HOME}/.kde" ## Just in case it's not already defined.
LOGDIR=/tmp/kde-${USER}
alias echo='echo -e'
if [ "${1}" ];then
## If a log file was specified, assign it. Also re-assign the log directory:
LOGFILE="${1##*/}" LOGDIR="${1%/*}"
test -z "${LOGDIR}" && LOGDIR="${PWD}" || LOGDIR="${LOGDIR#file://}"
else ## Else find the latest log file
LOGS=($(cd ${LOGDIR}; ls konqueror-crash-??????.log))
LOGCOUNT=${#LOGS[@]}
## Try to find log files which are newer than the one being tested:
for ((IND=0; IND<LOGCOUNT; IND++));do
FIND=$(cd ${LOGDIR}; find -type f -prune -name 'konqueror-crash-??????.log' -newer "${LOGS[${IND}]}")
## There can only be one file which is the latest, which means we stop:
test -z "${FIND}" && LOGFILE="${LOGS[${IND}]}" && break
done
test -z "${LOGFILE}" &&
{ echo "${PROG}: Cannot find any crash logs to recover.\n" && exit 1;}
unset IND LOGS LOGCOUNT
fi
## Sanity check:
test -r "${LOGDIR}/${LOGFILE}" ||
{ echo "${PROG}: Cannot read '${LOGFILE}'\n" && exit 1;}
URLFILE="${LOGFILE%.*}.urls"
## Read log file and build URL file list:
CLOSE=$(sed -r 's/^close([(].+[)]):.+/\1/' <(grep '^close[(]' "${LOGDIR}/${LOGFILE}"))
OPENED=$(sed -r 's/[%]2B/+/g' <(grep '^opened' "${LOGDIR}/${LOGFILE}" | grep -v "$CLOSE") | tac)
HEXNUM=$(sed -r 's/^.+([(].+[)]):.*/\1/' <<<"${OPENED}")
## One long parsing command to data mine the URLs and build the list file:
while read;do
nl <<<"${HEXNUM}" | sort -u -k2 | grep "${REPLY}"
done <<<"${HEXNUM}" | sort -u | cut -f2 | while read num;do
grep "${num}" <<<"${OPENED}" | line
done | tac | cut -d: -f2- > "${KDEHOME}/${URLFILE##*/}"
## Reset the new URL list timestamp to the original crash log's timestamp:
touch -r ${LOGDIR}/${LOGFILE} ${KDEHOME}/${URLFILE##*/}
echo "-->\tKonqueror session URLS are saved in \"${KDEHOME}/${URLFILE##*/}\""
exit 0
konqrestoreCode:
#! /bin/bash
################################################################################
##
## konqrestore: Opens a new KDE Konqueror browser window and populates it from
## a list of URLs, one line per URL, or a Konqueror crash log.
## Requires it's companion script, log2url, for directly restoring
## crash logs.
##
## Usage: konqrestore [url_list|logfile]
## 'url_list' or 'logfile' is an optional argument
##
## Written by CTWaley - Sep 2006.
##
## Freely given to the public domain by the author
##
################################################################################
readonly PROG="${0##*/}"
KDEHOME="${HOME}/.kde" ## Just in case it's not already defined.
PROFILE='webbrowsing' ## The Konqueror profile for restoring sessions
type -p log2url >/dev/null ||
{ echo "${PROG}: Cannot find required script 'log2url'" && exit 1;}
if [ "${1}" ];then
## If a file was specified, assign it. Also re-assign the file's directory:
FILE="${1##*/}"; FILEDIR="${1%/*}"
test -z "${FILEDIR}" && FILEDIR="${PWD}" || FILEDIR="${FILEDIR#file://}"
## Are we dealing with a crash log or URL list?:
egrep -qs '^opened[(][0-9a-f]+[)]:.+:.+$' "${FILEDIR}/${FILE}" &&
{ ## If dealing with a crash log, convert to an URL list:
log2url "${FILEDIR}/${FILE}"
## And point FILE and FILEDIR to the new file and location:
FILE="${FILE%.*}.urls"; FILEDIR="${KDEHOME}";}
else ## Else find the latest URL list file:
FILEDIR="${KDEHOME}"
FILES=($(cd ${FILEDIR}; ls konqueror-*.urls))
FILECOUNT=${#LOGS[@]}
## Try to find files which are newer than the one being tested:
for ((IND=0; IND<FILECOUNT; IND++));do
FIND=$(cd ${FILEDIR}; find -type f -prune -name 'konqueror-*.urls' -newer "${FILES[${IND}]}")
## There can only be one file which is the latest, which means we stop:
test -z "${FIND}" && FILE="${FILES[${IND}]}" && break
done
## Sanity check:
test -z "${FILE}" &&
{ echo -e "${PROG}: Cannot find any crash logs to recover.\n" && exit 1;}
unset IND FILES FILECOUNT
fi
## Sanity check:
test -r "${FILEDIR}/${FILE}" ||
{ echo -e "${PROG}: Cannot read '${FILE}'\n" && exit 1;}
## Input the list of URLs into an array:
URLS=($(while read;do egrep '^[a-z]+:.+$' <<<"${REPLY}"; done \
<<<"$(cat "${FILEDIR}/${FILE}")"))
## Any URLs found?:
test "${#URLS[@]}" == "0" &&
{ echo "${PROG}: ${FILEDIR}/${FILE}: No URL found" && exit 1;}
TABCOUNT=${#URLS[@]}
## Open a new browser window with the first URL in the list:
kfmclient openProfile "${PROFILE}" "${URLS[0]}"
## Now open up new tabs in the new browser window with the rest of the URLs:
for ((IND=1; IND<TABCOUNT; IND++));do
sleep 1
kfmclient newTab ${URLS[${IND}]}
done
Enjoy
---thegeekster