路由器(Router)是连接两个或多个网络的硬件设备,在网络间起网关的作用,是读取每一个数据包中的地址然后决定如何传送的专用智能性的网络设备,路由器最主要的功能为实现信息的转送。 将路由器作下载器有时会遇到内存居高不下,需要添加虚拟内存做后援。一般虚拟内存设为32M 或64M即可,再大没有意义,拖慢速度。如果实在不明白此脚本的功能,何须介意,不必强开。 按照下面的教程,先开启路由器的SSH和JFFS功能。 一、软配置:1)登录路由器,进入【系统管理】设置页面 2)进入【系统设置】选项,打开JFFS2和SSH功能 3)下拉到底,应用设置后,重启路由器生效。 4)下载WinSCP (点我下载 密码:6q52) 5)输入路由器IP,SCP协议,用户名、密码登录
6)进入路由器主目录/
10)选择UTF-8编码,然后将下面脚本代码复制到编辑器,并保存 #!/bin/sh R_BOLD="[31m[1m" G_BOLD="[32m[1m" BOLD="[33m[1m" NORM="[0m" INFO="$BOLD Info: $NORM" ERROR="$BOLD *** Error: $NORM" INPUT="$BOLD => $NORM" SWAP_FILE=`nvram get apps_swap_file` SWAP_SIZE=`nvram get apps_swap_size` i=1 cd /tmp echo -e "$INFO This script will guide you through the swap installation." echo -e "$INFO Script modifies "swap" folder only on the chosen drive," echo -e "$INFO Looking for available partitions..." for mounted in `/bin/mount |awk '{if($0 ~/mnt/){ print $3}}'` ; do echo -e "$G_BOLD [$i] --> $mounted $NORM" eval mounts$i=$mounted i=`expr $i + 1` done if [ $i == "1" ] ; then echo -e "$ERROR $R_BOLD No partitions available. Exiting...$NORM" exit 1 fi echo -en "$INPUT $BOLD Please enter partition number or 0 to exit $NORM $BOLD[0-`expr $i - 1`]$NORM: " read partitionNumber if [ "$partitionNumber" == "0" ] ; then echo -e $INFO Exiting... exit 0 fi if [ "$partitionNumber" = "" ] || [ "`echo $partitionNumber|sed 's/[0-9]//g'`" != "" ] ; then echo -e "$ERROR $R_BOLD Invalid arguments! Exiting...$NORM" exit 1 fi if [ "$partitionNumber" -gt `expr $i - 1` ] ; then echo -e "$ERROR $R_BOLD Invalid partition number! Exiting...$NORM" exit 1 fi eval entPartition=$mounts$partitionNumber echo -e "$INFO $G_BOLD $entPartition $NORM selected." APPS_INSTALL_PATH=$entPartition/swap case "$1" in start) mem_size=`free |awk '$0 ~/Swap/{print $4}'` pool_size=`df |awk '{if($0 ~"'$entPartition'") {print $4}}'` if [ $pool_size -gt $SWAP_SIZE ]; then [ -e "$APPS_INSTALL_PATH/$SWAP_FILE" ] && swapoff $APPS_INSTALL_PATH/$SWAP_FILE [ -d "$APPS_INSTALL_PATH" ] && rm -rf $APPS_INSTALL_PATH echo -e "$INFO Creating $APPS_INSTALL_PATH folder..." mkdir -p $APPS_INSTALL_PATH echo -en "$INFO Swap size is [$BOLD$SWAP_SIZE$NORM],changed:c $BOLD" read answer if [ "$answer" = "" ] then { echo -e "$INFO Swap size was not changed" } else { if [ "$answer" != "" ] && [ "`echo $answer|sed 's/[0-9]//g'`" = "" ] && [ $answer -lt $pool_size ] then { SWAP_SIZE=$answer echo -en "$INFO Swap size was changed $BOLD[$SWAP_SIZE]$NORM " } else { echo -e "$ERROR $R_BOLD Invalid arguments $NORM" exit 1 } fi } fi swap_count=`expr $SWAP_SIZE / 1000 - 1` echo -e "$INFO dd if=/dev/zero of=$APPS_INSTALL_PATH/$SWAP_FILE bs=1M count=$swap_count" dd if=/dev/zero of=$APPS_INSTALL_PATH/$SWAP_FILE bs=1M count=$swap_count echo -e "$INFO mkswap $APPS_INSTALL_PATH/$SWAP_FILE" mkswap $APPS_INSTALL_PATH/$SWAP_FILE echo -e "$INFO $G_BOLD swapon $APPS_INSTALL_PATH/$SWAP_FILE $NORM" swapon $APPS_INSTALL_PATH/$SWAP_FILE echo -e "**********************************************************" echo -e " ${G_BOLD}Swap:$NORM Total($G_BOLD$(free |grep -A1 "Swap" |awk '{print $2}')$NORM) Used($G_BOLD$(free |grep -A1 "Swap" |awk '{print $3}')$NORM) Free($G_BOLD$(free |grep -A1 "Swap" |awk '{print $4}')$NORM)" echo -e "**********************************************************" fi echo -e "$INFO Create boot entry, y? :c " read yor if [ "$yor" = "y" ] then { [ -e "/jffs/scripts/services-start" ] && [ `cat /jffs/scripts/services-start |awk '{if($0 ~/swapon/) {print $0}}'|wc -l` -ge 1 ] && sed -i 'N;/ .*swapon/!P;D' /jffs/scripts/services-start && sed -i '/swapon/d' /jffs/scripts/services-start [ ! -e "/jffs/scripts/services-start" ] && echo "#!/bin/sh" > /jffs/scripts/services-start [ `grep "#!/bin/sh" /jffs/scripts/services-start |wc -l` -lt 1 ] && sed -i '1i#!/bin/sh' /jffs/scripts/services-start sed -i '1asleep 30' /jffs/scripts/services-start sed -i '2aswapon '$APPS_INSTALL_PATH'/'$SWAP_FILE'' /jffs/scripts/services-start chmod 755 /jffs/scripts/services-start echo -e "$INFO $G_BOLD Boot entry is created $NORM" } else { echo -e "$INFO $G_BOLD Boot entry was not created,Exiting $NORM" exit 1 } fi ;; stop) [ -e "/jffs/scripts/services-start" ] && [ `cat /jffs/scripts/services-start |awk '{if($0 ~/swapon/) {print $0}}'|wc -l` -ge 1 ] && sed -i 'N;/ .*swapon/!P;D' /jffs/scripts/services-start && sed -i '/swapon/d' /jffs/scripts/services-start [ -e "$APPS_INSTALL_PATH/$SWAP_FILE" ] && swapoff $APPS_INSTALL_PATH/$SWAP_FILE [ -d "$APPS_INSTALL_PATH" ] && rm -rf $APPS_INSTALL_PATH echo -e "**********************************************************" echo -e " ${G_BOLD}Swap:$NORM Total($G_BOLD$(free |grep -A1 "Swap" |awk '{print $2}')$NORM) Used($G_BOLD$(free |grep -A1 "Swap" |awk '{print $3}')$NORM) Free($G_BOLD$(free |grep -A1 "Swap" |awk '{print $4}')$NORM)" echo -e "**********************************************************" ;; *) exit 1 ;; esac
11)在sdaswap文件右击鼠标,属性。设置为0755权限 (该权限是可读写、执行) 二、执行命令1)进入路由器的软件中心 Software Center 安装shellinabox命令工具 2)运行命令行:/jffs/scripts/sdaswap start 3)脚本自动扫描路由器外接的USB设备,列出所有存储类设备供选择使用哪个USB硬盘作为虚拟内存的载体。 4)加载成功后,自动加载Swap的信息。Total是总缓存,Used 已使用,Free未使用 5)停用虚拟内存功能命令:/jffs/scripts/sdaswap stop 下面是增加虚拟内存前后的结果图
本文可以帮助您基本地设置和管理您的路由器。 |
温馨提示:喜欢本站的话,请收藏一下本站!