#!/bin/sh # This script is to stop all the whining about # "setting up asppp is too hard!!! whine whine..." # # written by phil@bolthole.com # NOTES: # should test the line # should TRY to selfdiagnose. FOr example: /etc/log/asppp.log # Call Failed: CAN'T ACCESS DEVICE # version='v1.2' echo "configppp.sh, by phil@bolthole.com: http://www.bolthole.com/solaris/" echo version $version OSREV=`uname -r` CONFIGFILE=/etc/configppp.cf #because older bundled PPP versions sucked, we dont try #to run on older systems. case $OSREV in 5.2) echo "OS too old. sorry" exit ;; 5.3) echo "OS too old. sorry" exit ;; 5.4) echo "OS too old. sorry" exit ;; esac val=ROOT #val=`id | sed 's/uid=0(.*/ROOT/'` if [ "$val" != "ROOT" ] ; then echo "" echo "Sorry, you are also expected to be root to run this script" exit 1 fi # #Skip down to next set of ####, if you care about main stuff. ############################################################ # we 'echo' our return value. So we have to prompt out to stderr getvalue() { echo $1 >/dev/fd/2 echo "Enter new value, or press return to keep default" >/dev/fd/2 read line echo $line } #specialized version of getvalue() # [we 'echo' our return value. So we have to prompt out to stderr] # give it the message, and default value of a variable # It will prompt the user # It will either # - print out a new value for the param and return 0, or # - return 1 (which means, stop here) # It will return 1 **if** # - the user types "end" # - the user enters nothing, and there is no default getchat() { msg="$1" default="$2" echo $msg "[$default]">/dev/fd/2 read line if [ "$line" = "end" ] ; then return 1 fi if [ "$line" = "" ] ; then if [ "$default" = "" ] ; then return 1 fi echo $default return 0 fi echo $line return 0 } ############################################################ if [ -f $CONFIGFILE ] ; then . $CONFIGFILE fi MODEMDEV=${MODEMDEV:="Any"} echo Starting automated setup for single ppp connection to an ISP echo "We assume the following:" echo "*** I am not to be held resposible for any errors in this script that result" echo "** in damage to your system in any way" echo "" echo "* You haven't messed around with the /etc/uucp, or /etc/asppp.cf stuff" echo "* You already know what the login strings look like for your ISP," echo " not to mention the appropriate dialin number" echo "" echo checking for components if [ ! -f /etc/asppp.cf ] ; then echo you do not have all the ppp packages installed. Cannot continue exit fi if [ ! -f /etc/uucp/Systems ] ; then echo you do not have all the uucp packages installed. Cannot continue exit fi echo 'Checking for backup files. Do not ever remove any files named *pre_ppp' for file in /etc/asppp.cf /etc/uucp/Systems /etc/uucp/Devices ; do if [ ! -f ${file}-pre_ppp ] ; then echo making backup of $file cp $file ${file}-pre_ppp fi done echo "" LOCALNAME=${LOCALNAME:-mypppside} #we assume dynamic ppp in this day and age # 1.2.3.4 is the sun-given "dummy" IP suggestion LOCALIP=${LOCALIP:-1.2.3.4} echo "####################" echo NOTICE: echo 'We are calling the remote side "ispside". ' echo We will override any other entry you may have for host '"ispside"' echo "" REMOTENAME=${REMOTENAME:-ispside} # This needs to be non-wierd, so we can ping it if need be REMOTEIP=${REMOTEIP:-5.6.7.8} ans=`getvalue "Current ISP-side IP addr is $REMOTEIP"` REMOTEIP=${ans:=$REMOTEIP} echo "" echo "If you do not know the DNS IP address for your ISP, just use the same as" echo "the remote-side IP" DNS=${DNS:=$REMOTEIP} ans=`getvalue "What is your ISP's DNS server IP address? ($DNS)"` DNS=${ans:=$DNS} echo "" echo Do not change the following value unless you KNOW you have a static IP echo You probably do NOT have a static IP nowadays ans=`getvalue "Current local-side IP addr is $LOCALIP"` LOCALIP=${ans:=$LOCALIP} ISPNUMBER=${ISPNUMBER:="No default"} echo "" echo "The best thing to try at first is the default 'Any'" echo "otherwise, try 'cua/a' or 'cua/b'" ans=`getvalue "What modem device would you like to use? ($MODEMDEV)"` MODEMDEV=${ans:=$MODEMDEV} echo "What speed would you like to use?" cpu=`uname -p` case $cpu in 'sparc') echo "you're on a sparc. You probably don't want to use" echo "higher than 38400, unless you have a new serial port, and/or" echo "a special modem" ;; 'i86pc') echo "You're on a PC. You PROBABLY have a serial port that can" echo "handle 115200 bps" ;; esac choice=0 while [ $choice -eq 0 ] ; do BAUDLIST="9600 19200 38400 57600 76800 115200" ans=`getvalue "pick from $BAUDLIST ($BAUDRATE)"` if [ "$ans" = "" ] ; then ans=$BAUDRATE fi for bl in $BAUDLIST ; do if [ "$ans" = "$bl" ] ; then choice=$ans BAUDRATE="$ans" fi done done while [ "$ISPNUMBER" = "No default" ] ; do ans=`getvalue "What's the telephone dialin number of your ISP? ($ISPNUMBER)"` ISPNUMBER=${ans:=$ISPNUMBER} done chatdirections() { echo "____________________________________________________________" echo "" echo "Now we get to the part you'll probably have to play with the most." echo "You should have dialed in to the above number, and know what the text" echo "looks like when starting up ppp, so we know what to expect" echo "" echo "EXAMPLE: Lets say your ISP prompts you with" echo " Annex server xxxxxxxx Welcome to uber-kontrol ISP please login: [ you type your login here] what's your password? [you type your password here]" echo "" echo "You would set the first thing we look for as 'gin:'" echo "since that is the last thing we look for before actually " echo "sending something back" echo "Then, set [yourloginname] as what we reply with." echo "Next, the second thing we look for would be 'ord?'" echo "which is the last four letter of 'password?'" echo "After that, set what we reply with, to be your password" echo "" echo "Just press return when you don't have anything more, and we'll move" echo "on to actually setting things up" echo "" echo "____________________________________________________________" } # This reads in the chat script answers. The trick here is # if they enter a blank line, and there is no default, we # then have to null out all the later answers setchatscript() { echo "Most ISPs require a basic chat script along the following lines" echo "(look for): login" echo "(reply with): your-dial-up-name" echo "(look for): word" echo "(reply with): your-dial-up-password" echo "" echo "To end the script, or take the default, press return." echo "If you want to override a default and quit, enter 'end'" echo "" EXPECT1=`getchat "What's the first thing we should look for?" $EXPECT1` if [ $? -ne 0 ] ; then echo "I sure hope you know what you're doing" EXPECT2=""; EXPECT3="" EXPECT4=""; SEND1="" SEND2=""; SEND3="" SEND4="" return; fi SEND1=`getchat "What should we reply with?" $SEND1` if [ $? -ne 0 ] ; then echo "I sure hope you know what you're doing" EXPECT2=""; EXPECT3="" EXPECT4=""; SEND2="" SEND3=""; SEND4="" return; fi EXPECT2=`getchat "What's the second thing we should look for?" $EXPECT2` if [ $? -ne 0 ] ; then EXPECT3=""; EXPECT4="" SEND2=""; SEND3="" SEND4="" return; fi SEND2=`getchat "What should we reply with?" $SEND2` if [ $? -ne 0 ] ; then EXPECT3=""; EXPECT4="" SEND3=""; SEND4="" return; fi EXPECT3=`getchat "What's the third thing we should look for?" $EXPECT3` if [ $? -ne 0 ] ; then EXPECT4=""; SEND3=""; SEND4="" return; fi SEND3=`getchat "What should we reply with?" $SEND3` if [ $? -ne 0 ] ; then EXPECT4=""; SEND4="" return; fi EXPECT4=`getchat "What's the last thing we should look for?" $EXPECT4` if [ $? -ne 0 ] ; then SEND4="" return; fi SEND4=`getchat "What should we reply with? [$SEND4]"` } export EXPECT1 EXPECT2 EXPECT3 EXPECT4 export SEND1 SEND2 SEND3 SEND4 chatdirections | more USEPAP=${USEPAP:-n} USECHAP=${USECHAP:-n} USECHAT=${USECHAT:-y} echo "Do you want to use 'PAP' or 'CHAP'?" ans=`getvalue "Use PAP [$USEPAP]?"` if [ "$ans" = "y" -o "$ans" = "Y" -o "$ans" = "yes" ] ; then USEPAP="y" else USEPAP=${ans:=$USEPAP} fi if [ $USEPAP != "y" ] ; then ans=`getvalue "Use CHAP[$USECHAP]?"` if [ "$ans" = "y" -o "$ans" = "Y" -o "$ans" = "yes" ] ; then USECHAP="y" else USECHAP=${ans:=$USECHAP} fi fi if [ $USECHAP = "y" -o $USEPAP = "y" ] ; then echo USECHAP=$USECHAP echo USEPAP=$USEPAP ans=`getvalue "What's your PPP login name? [$LOGIN]"` LOGIN=${ans:=$LOGIN} ans=`getvalue "And your PPP password? [$PASSWORD]"` PASSWORD=${ans:=$PASSWORD} EXPECT1="" EXPECT2="" EXPECT3="" EXPECT4="" SEND1="" SEND2="" SEND3="" SEND4="" fi echo "Do you want to make a chat script (y/n)?" ans=`getvalue "(Most ISPs require a basic one) [$USECHAT]"` USECHAT=${ans:=$USECHAT} if [ $USECHAT = "y" -o $USECHAT = "Y" ] ; then setchatscript fi echo "Happy with your answers? enter 'y' to continue" read ans if [ "$ans" != "y" -a "$ans" != "Y" ] ; then echo "Okay, quitting now." exit fi # Save config answers. Then do actual setup. echo "Saving new defaults" echo REMOTENAME=$REMOTENAME | tee $CONFIGFILE #security, security... chmod 0600 $CONFIGFILE echo REMOTEIP=$REMOTEIP | tee $CONFIGFILE echo DNS=$DNS | tee -a $CONFIGFILE echo LOCALNAME=$LOCALNAME | tee -a $CONFIGFILE echo LOCALIP=$LOCALIP | tee -a $CONFIGFILE echo ISPNUMBER=$ISPNUMBER | tee -a $CONFIGFILE echo LOGIN=$LOGIN | tee -a $CONFIGFILE echo PASSWORD=$PASSWORD | tee -a $CONFIGFILE echo USEPAP=$USEPAP | tee -a $CONFIGFILE echo USECHAP=$USECHAP | tee -a $CONFIGFILE echo USECHAT=$USECHAT | tee -a $CONFIGFILE echo EXPECT1=$EXPECT1 | tee -a $CONFIGFILE echo EXPECT2=$EXPECT2 | tee -a $CONFIGFILE echo EXPECT3=$EXPECT3 | tee -a $CONFIGFILE echo EXPECT4=$EXPECT4 | tee -a $CONFIGFILE echo SEND1=$SEND1 | tee -a $CONFIGFILE echo SEND2=$SEND2 | tee -a $CONFIGFILE echo SEND3=$SEND3 | tee -a $CONFIGFILE echo SEND4=$SEND4 | tee -a $CONFIGFILE echo MODEMDEV=$MODEMDEV | tee -a $CONFIGFILE echo BAUDRATE=$BAUDRATE | tee -a $CONFIGFILE if [ "$MODEMDEV" != "ACU" ] ; then DEVTYPE="CONFPPP" else DEVTYPE="ACU" fi ################################################## if [ -f /etc/resolv.conf ] ; then if [ ! -f /etc/resolv.conf-pre_ppp ] ; then echo backing up /etc/resolv.conf cp /etc/resolv.conf /etc/resolv.conf-pre_ppp fi fi echo setting up /etc/resolv.conf echo "nameserver $DNS" >/etc/resolv.conf ######## grep '^hosts:.*dns' /etc/nsswitch.conf if [ $? -ne 0 ] ; then echo adding dns to /etc/nsswitch.conf sed 's/\(hosts:.*\)/\1 dns/' /etc/nsswitch.conf >/tmp/ns.$$ mv /tmp/ns.$$ /etc/nsswitch.conf fi ##### echo setting up /etc/hosts TMPHOSTS=/tmp/hosts.$$ sed -e "s/^$REMOTEIP.*/$REMOTEIP $REMOTENAME/" -e "s/^$LOCALIP.*/$LOCALIP $LOCALNAME/" /etc/hosts >$TMPHOSTS if [ $? -ne 0 ] ; then echo error copying /etc/hosts: quitting exit 1 fi grep $REMOTENAME $TMPHOSTS >/dev/null if [ $? -eq 0 ] ; then echo setting IP of $REMOTENAME to $REMOTEIP sed -e "s/.*${REMOTENAME}.*/$REMOTEIP $REMOTENAME/" $TMPHOSTS >/tmp/t.$$ mv /tmp/t.$$ $TMPHOSTS else echo adding remote IP to hosts file echo $REMOTEIP $REMOTENAME >>$TMPHOSTS fi grep $LOCALNAME $TMPHOSTS >/dev/null if [ $? -ne 0 ] ; then echo adding local IP to hosts file echo $LOCALIP $LOCALNAME >>$TMPHOSTS fi cp $TMPHOSTS /etc/hosts if [ $? -ne 0 ] ; then echo error copying. leaving tmp file $TMPHOSTS and quitting exit 1 fi rm $TMPHOSTS ####### ############################################################ #I think/hope this will work on both sparc and intel # It is recommended that this actually goes in "Devices", but # to make my life simple, I'm going to put it in Dialers instead. # UUCP_PREAMBLE='"" P_ZERO' # This doesnt seem to work here :-( # "" STTY=crtscts' echo setting up uucp dialin stuff cd /etc/uucp cp Systems-pre_ppp Systems if [ "$MODEMDEV" = "ACU" ] ; then echo $REMOTENAME Any ACU $BAUDRATE $ISPNUMBER $UUCP_PREAMBLE $EXPECT1 $SEND1 $EXPECT2 $SEND2 $EXPECT3 $SEND3 $EXPECT4 $SEND4 >>Systems else MODEMDEV=`echo $MODEMDEV |sed 's:/dev/::'` echo $REMOTENAME Any CONFPPP $BAUDRATE $ISPNUMBER $UUCP_PREAMBLE $EXPECT1 $SEND1 $EXPECT2 $SEND2 $EXPECT3 $SEND3 $EXPECT4 $SEND4 >>Systems egrep -v CONFPPP Devices >/tmp/dev.$$ mv /tmp/dev.$$ Devices echo CONFPPP $MODEMDEV - Any hayes >>Devices fi echo setting up asppp demon cd /etc cp asppp.cf-pre_ppp asppp.cf INTERFACE=ipdptp0 echo "#The following is auto-entered by configppp.sh" >>asppp.cf echo ifconfig $INTERFACE plumb $LOCALNAME $REMOTENAME up >>asppp.cf echo "" >>asppp.cf echo "path" >>asppp.cf echo " interface $INTERFACE" >>asppp.cf echo " peer_system_name $REMOTENAME" >>asppp.cf if [ $USEPAP = "y" ] ; then echo " pap_id $LOGIN" >>asppp.cf echo " pap_password $PASSWORD" >>asppp.cf fi if [ $USECHAP = "y" ] ; then echo " chap_name $LOGIN" >>asppp.cf echo " chap_secret $PASSWORD" >>asppp.cf fi echo " negotiate_address on" >>asppp.cf echo " inactivity_timeout 300" >>asppp.cf echo " default_route" >>asppp.cf echo "" >>asppp.cf echo "" echo "" echo "############################################################" echo "setting default route" if [ -f /etc/defaultrouter ] ; then echo used to be cat /etc/defaultrouter fi echo ispside >/etc/defaultrouter echo "Okay, we're done! Starting dialup PPP demon..." /etc/init.d/asppp stop >/dev/null 2>&1 sleep 1 /etc/init.d/asppp start echo "BTW, if you dont want your link to come up at boot-time, change the" echo " keep-hot-count hosts" echo " line in /etc/nscd from value 20, to 0" echo "" echo "" echo "If something isn't working, run this script again and change your answers" echo "" echo "" echo "PLEASE EMAIL phil@bolthole.com to say whether or not this script works" echo " for you. I will try to iron out any problems in the script you may" echo " encounter, and thus help even more people by your feedback." echo "" echo "For testing, do '/usr/sbin/ping ispside' to try to bring up the connection" #!/bin/sh # diag /usr/platform/`uname -i`/sbin/prtdiag -v /usr/platform/`uname -i`/sbin/eeprom #! /bin/sh echo "format" echo "awk '{print \$2}' drv | sed '/^\$/d' | sed 's/\$/s2/'> drives" echo "while read line" echo "do" echo "/usr/sbin/prtvtoc /dev/dsk/\$line >> drives.info" echo "done /dev/null` case $_fl_output in l*) _fp_next=`echo "$_fl_output" | awk '{print $NF}'` (cd `dirname $1`; findlink "$_fp_next" "$2 $1") ;; '') # leads to nothing, should the filename be printed instead? echo $2 @ ;; *) echo $2 $1 ;; esac unset _fp_result _fp_output } #! /bin/sh # step in the process # 1999-04-05 Rafael Skodlar diff_file="src+dst_dir_diff.0" f2m="./files2move" date=`date` i=1 while read line do dir_src=`echo $line|awk '{print $1}'` dir_dst=`echo $line|awk '{print $2}'` # grab disk src_disk=`echo $dir_src|awk -F/ '{print $3}'` dst_disk=`echo $dir_dst|awk -F/ '{print $3}'` readme=$dir_dst/README #readme=README.$src_disk # Put README file in top directory echo " SRC Disk: $src_disk --> $dir_src" echo " DST Disk: $dst_disk --> $dir_dst" echo " README loc: $readme" cat << EOM > $readme Following links to nonexisting files were found on: $dir_src during file transfer to: $dir_dst $date ============================================== crm+@postcard.eng.sun.com ==== EOM grep $src_disk $diff_file | while read link do #ls -l $link >> $readme echo subs: $src_disk / $dst_disk ls -l $link | sed 's/$src_disk/$dst_disk/'>> $readme ls -l $link | sed 's/$src_disk/$dst_disk/' #sleep 3 done i=`expr "$i" + 1` done < $f2m #! /bin/sh # create metapartitions # # 1999-04-10 Rafael Skodlar # top_dir=/tmp partitions_raw=$top_dir/partitions_raw partitions=$top_dir/partitions log=$top_dir/meta.log # mounting points: /export/mdisk3/blaze per line mpoints=/tmp/mpoints #if [ -e $partitions ] #then #cat $partitions while read part do mdisk=`echo $line|awk -F/ '{print $5}'` echo "----> mdisk= $mdisk" /usr/opt/SUNWmd/sbin/metainit $mdisk /usr/sbin/newfs -i 8192 -m 5% $line fsk $part dir=`echo $mdisk|sed 's/d/mdisk/'` echo "Create Dir: $top_mount/$dir" mkdir $top_mount/$dir chmod g-s $dir chmod 775 $dir done < $partitions_raw echo "Finished creating meta partitions" # mount meta partitions while read part do mount $part $dir done < $partitions echo partitions mounted" * force hme interfaces to full duplex set hme:hme_adv_autoneg_cap=0 set hme:hme_adv_100hdx_cap=0 set hme:hme_adv_100fdx_cap=1 * end hme cd /etc vi system tail system #!/bin/sh # clean log files ARCHIVE="OLD" if [ $# -lt 2 ]; then echo "usage: newlog dir name" exit 1 fi # # calculate suffix for current log files suffix='date +%y%m%d' # # move to specified log directory cd $1 shift # # iterate through each named log file while [ x$1 != x ]; do mv -f $1 $ARCHIVE/$1.$suffix cp /dev/null $1 chmod 640 $1 shift done # # tickle syslog to get it to use the new log files kill -1 'cat /etc/syslog.pid' # # wait for syslog to switch over sleep 5 # # now compress the freshly archived logs compress $ARCHIVE/*.$suffix #!/bin/csh $ for x in *txt; do mv $x `echo $x | sed s/txt/doc/`; done #!/usr/bin/perl # redate - move file to foo-19981211 # tchrist@perl.com # Sat Apr 17 20:08:27 MDT 1999 $oops = 0; if (@ARGV && $ARGV[0] eq '-n') { shift; $nonono = 1; } die "usage: $0 [-n] filename ...\n" unless @ARGV; for $file (@ARGV) { next if $file =~ /-\d{8}$/; # already done unless ($mtime = (stat($file))[9]) { warn "$0: can't stat $file: $!\n"; $oops++; } ($day, $month, $year) = (localtime($mtime))[3,4,5]; $then = sprintf "%4d%02d%02d", $year + 1900, $month + 1, $day; if ($nonono) { print "rename $file $file-$then\n"; next; } next if rename($file, "$file-$then"); warn "$0: can't rename `$file' to `$file-$then': $!\n"; $oops++; } exit ($oops != 0); __END__ #! /bin/sh # 1999-04-28 Rqafael Skodlar # if [ $# -lt 2 ] then echo " Usage: $0 user printer." exit fi user=$1 printer=$2 log=/tmp/lpq.$printer echo "User: $user printer: $printer" lpq -P$printer > $log awk '{print $3}' $log > $log_jobs i=`wc -l $log_jobs` echo "About to remove $i jobs for the user: $user on $printer" while read $job do lprm -P$plotter $job echo "Job $job removed, $i to go" $i=`expr "$i" - 1` done < $log_jobs echo "Complete." #!/bin/sh # System Status Report # 1999-05-27 Rafael Skodlar HOST=`/bin/uname -n` DATE=`/bin/date '+%Y%m%d_%H` USER=`/usr/ucb/whoami` LOG_DIR="/home/$USER/admin/logs/syslogs/$HOST" LOG_FILE=$LOG_DIR/$DATE echo $LOG_FILE if [ ! -d $LOG_DIR ] then mkdir $LOG_DIR fi echo "===== Logins =================================================================" > $LOG_FILE w >> $LOG_FILE echo "===== last -5 ================================================================" > $LOG_FILE last -5 >> $LOG_FILE echo "===== df -kl =================================================================" >> $LOG_FILE df -kl >> $LOG_FILE echo "===== vmstat =================================================================" >> $LOG_FILE vmstat 5 3 >> $LOG_FILE echo "===== iostat =================================================================" >> $LOG_FILE iostat 5 3 >> $LOG_FILE iostat -E >> $LOG_FILE echo "===== mpstat =================================================================" >> $LOG_FILE mpstat 5 3 >> $LOG_FILE echo "===== netstat ================================================================" >> $LOG_FILE netstat | awk '/UNIX/{exit}{print}' | grep -v local >> $LOG_FILE echo "===== PS =====================================================================" >> $LOG_FILE ps -ef >> $LOG_FILE #!/bin/sh # trim huge selected log files (> MAX_SIZE), preserve last 1000 lines of logs # in *.tail files for troubleshooting # # 1998-12-01 Rafael Skodlar MAX_SIZE=2000000 LOG_FILE=/var/adm/messages #LOG_FILE=/var/log/news/ TMP=~/tmp NEWS=$TMP/news.logs BIGLOG=$TMP/big.news.logs #for file in (ls -l $LOG_FILE | awk '{if($5 > $MAX_SIZE)print $9}}') /bin/ls -l $LOG_FILE > $NEWS cat ${NEWS}|/bin/awk '{if($5 > 2000000)print $9}' > ${BIGLOG} for file in `cat ${BIGLOG}` do TAIL_FILE=${LOG_FILE}/tails/$file.tail tail -1000 $LOG_FILE/$file >$TAIL_FILE cp /dev/null $LOG_FILE/$file echo trimmed log: $file done echo "Done trimming log files."