1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Free up memory

Discussion in 'Tomato Firmware' started by jan.n, Oct 28, 2009.

  1. jan.n

    jan.n Addicted to LI Member

    I recently saw that I don't have much free RAM left.
    How do I free up memory?

    AFAIK dropping idle connections from the conntrack table is helpful, but are there other things to do?
     
  2. landa

    landa LI Guru Member

    You can try a NVRAM Commit.
     
  3. rhester72

    rhester72 Network Guru Member

    Administration/Debugging/Count cache memory as free memory

    Rodney
     
  4. Azuse

    Azuse LI Guru Member

    Free memory is the worst thing you can have on any computer. It's fast access data storage that's burning power, cpu cycles & achieving nothing. Tomato manages memory well (at least in my experience with the RAF mod), my dnsmasq is at 4096 & I can shove 8k connections through he router and still not make it run out. Mine typically hoveres between 6.5 & 0.9% free.
     
  5. Toastman

    Toastman Super Moderator Staff Member Member

    The best thing you can ever do is to time out your redundant TCP and UDP connections quickly. You can pare most Conntrack settings right down to the bone, after doing this it isn't really so often that your router will ever rise much above 1500 or so. Which keeps it fast and responsive.
     
  6. jan.n

    jan.n Addicted to LI Member

    OK, thank you all for the explanations.
    What are normal everyday readings of free memory?

    Mine now has 2912 KB free, is that average?
     
  7. TVTV

    TVTV LI Guru Member

    Mine says "Total / Free Memory - 14.15 MB / 6,092.00 KB (42.04%)" after setting "Administration/Debugging/Count cache memory as free memory" to ON. ;) Current uptime = 3 days, and memory reading was taken after a game of Quake Live.
     
  8. Toastman

    Toastman Super Moderator Staff Member Member

    jan.n There's nothing unusual with your router's memory useage. It will vary from day to day, it's nothing to worry about.
     
  9. jan.n

    jan.n Addicted to LI Member

    Thank you all
     
  10. spicoli

    spicoli LI Guru Member

    Just a Q, how much does logging and bandwidth logging take? I have both disabled for no reason and I would like to have em on for no reason if they don't take up much room. I'm thinking it depends on your uptime but, I could be wrong!
     
  11. Planiwa

    Planiwa LI Guru Member

    Tomato has no memory leaks. I wouldn't worry about free space unless it dropped below 700 kB. You will see it jump up and down in leaps of 500kB. Mine tends to range from 900 to 1600 kB, typically.

    Code:
                                                Con U Free Load  WAN:T-U   LAN:T-U  WAN Sys
    Oct 30 21:16:27 ROUTER user.notice root: VIT 78 4 1200 .1 . 2604-246 2571-1156 1d 4d
    Oct 30 21:25:03 ROUTER user.notice root: VIT 14 4 980 .0 . 2628-247 2594-1179 1d 4d
    Oct 30 21:55:02 ROUTER user.notice root: VIT 37 4 800 .0 . 2699-250 2665-1247 1d 4d
    Oct 30 21:58:18 ROUTER user.notice root: VIT 33 4 980 .0 . 2699-250 2666-1248 1d 4d
    Oct 30 22:25:04 ROUTER user.notice root: VIT 363 5 1672 .1 . 2791-254 2757-1336 1d 4d
    Oct 30 22:55:02 ROUTER user.notice root: VIT 14 5 1680 .0 . 2819-255 2785-1363 1d 4d
    Oct 30 23:25:04 ROUTER user.notice root: VIT 74 5 1672 .0 . 2910-258 2878-1453 1d 4d
    Oct 30 23:51:17 ROUTER user.notice root: VIT 96 5 1540 .1 . 3008-261 2976-1548 1d 5d
    Oct 30 23:55:02 ROUTER user.notice root: VIT 90 5 1196 .1 . 3027-261 2996-1567 1d 5d
    Oct 31 00:25:03 ROUTER user.notice root: VIT 205 5 1636 .0 . 3216-268 3187-1751 1d 5d
    Oct 31 00:55:02 ROUTER user.notice root: VIT 67 5 1644 .0 . 3325-273 3297-1856 1d 5d
    Oct 31 01:25:02 ROUTER user.notice root: VIT 51 5 1072 .0 . 3447-279 3420-1973 1d 5d
    Oct 31 01:55:03 ROUTER user.notice root: VIT 11 4 1620 .0 . 3560-284 3533-2082 1d 5d
    Oct 31 02:25:04 ROUTER user.notice root: VIT 12 3 1632 .0 . 3570-285 3545-2092 1d 5d
    Oct 31 02:55:02 ROUTER user.notice root: VIT 37 3 1640 .0 . 3598-287 3573-2118 1d 5d
    Oct 31 03:25:03 ROUTER user.notice root: VIT 6 2 1068 .0 . 3655-290 3631-2173 1d 5d
    Oct 31 03:55:02 ROUTER user.notice root: VIT 3 1 1620 .0 . 3666-292 3642-2182 1d 5d
    Oct 31 04:25:03 ROUTER user.notice root: VIT 5 1 1632 .0 . 3668-293 3645-2184 1d 5d
    Oct 31 04:55:02 ROUTER user.notice root: VIT 3 1 1640 .0 . 3671-294 3647-2186 1d 5d
    Oct 31 05:25:02 ROUTER user.notice root: VIT 4 1 1068 .1 . 3673-294 3650-2188 1d 5d
    Oct 31 05:55:03 ROUTER user.notice root: VIT 3 1 1620 .0 . 3683-296 3661-2197 1d 5d
    Oct 31 06:25:03 ROUTER user.notice root: VIT 5 1 1632 .0 . 3686-297 3664-2199 1d 5d
    Oct 31 06:55:02 ROUTER user.notice root: VIT 3 1 1640 .0 . 3690-298 3667-2201 1d 5d
    Oct 31 07:25:03 ROUTER user.notice root: VIT 5 1 1632 .0 . 3693-299 3671-2204 1d 5d
    Oct 31 07:55:02 ROUTER user.notice root: VIT 0 0 1640 .0 . 3695-299 3673-2206 1d 5d
    Oct 31 08:25:04 ROUTER user.notice root: VIT 3 0 1632 .0 . 3695-299 3673-2206 1d 5d
    Oct 31 08:55:02 ROUTER user.notice root: VIT 0 0 1640 .0 . 3695-299 3673-2206 1d 5d
    Oct 31 09:25:04 ROUTER user.notice root: VIT 2 0 1632 .0 . 3695-299 3673-2206 1d 5d
    Oct 31 09:55:02 ROUTER user.notice root: VIT 0 0 1640 .0 . 3695-299 3673-2206 1d 5d
    Oct 31 10:25:03 ROUTER user.notice root: VIT 33 2 1628 .0 . 3735-301 3714-2245 1d 5d
    Oct 31 10:55:02 ROUTER user.notice root: VIT 15 2 1636 .0 . 3896-304 3876-2404 1d 5d
    Oct 31 11:25:02 ROUTER user.notice root: VIT 70 2 1064 .0 . 3934-306 3914-2440 1d 5d
    Oct 31 11:55:02 ROUTER user.notice root: VIT 24 2 1616 .0 . 3999-308 3980-2504 1d 5d
    Oct 31 12:25:04 ROUTER user.notice root: VIT 45 2 1628 .0 . 4101-311 4083-2604 1d 5d
    Oct 31 12:55:02 ROUTER user.notice root: VIT 5 1 1636 .0 . 4116-312 4099-2619 1d 5d
    Oct 31 13:25:04 ROUTER user.notice root: VIT 8 1 1628 .0 . 4118-313 4100-2619 1d 5d
    Oct 31 13:55:02 ROUTER user.notice root: VIT 5 1 1636 .0 . 4119-313 4101-2620 1d 5d
    Oct 31 14:25:03 ROUTER user.notice root: VIT 7 2 1628 .0 . 4191-315 4175-2691 1d 5d
    Oct 31 14:55:02 ROUTER user.notice root: VIT 58 3 1636 .0 . 4205-317 4188-2703 1d 5d
    Oct 31 15:25:04 ROUTER user.notice root: VIT 59 3 1624 .0 . 4236-319 4220-2732 1d 5d
    Oct 31 15:55:02 ROUTER user.notice root: VIT 57 3 1628 .1 . 4296-323 4281-2789 1d 5d
    Oct 31 16:25:04 ROUTER user.notice root: VIT 247 3 1620 .0 . 4404-329 4391-2893 1d 5d
    Oct 31 16:55:02 ROUTER user.notice root: VIT 42 2 1628 .0 . 4428-333 4415-2913 1d 5d
    Oct 31 17:25:03 ROUTER user.notice root: VIT 27 3 1620 .0 . 4432-334 4419-2916 1d 5d
    Oct 31 17:55:02 ROUTER user.notice root: VIT 78 3 1624 .0 . 4441-336 4428-2924 1d 5d
    Oct 31 18:25:03 ROUTER user.notice root: VIT 58 3 1616 .0 . 4488-340 4477-2968 1d 5d
    Oct 31 18:55:03 ROUTER user.notice root: VIT 83 3 1624 .1 . 4585-345 4575-3061 2d 5d
    Oct 31 19:25:04 ROUTER user.notice root: VIT 31 3 1616 .0 . 489-352 4776-3255 2d 5d
    Oct 31 19:55:02 ROUTER user.notice root: VIT 45 3 1624 .0 . 663-358 4952-3425 2d 5d
    Oct 31 20:25:02 ROUTER user.notice root: VIT 15 3 1052 .0 . 699-361 4988-3458 2d 5d
    Oct 31 20:55:02 ROUTER user.notice root: VIT 66 3 1600 .0 . 719-363 5009-3477 2d 5d
    Oct 31 21:25:03 ROUTER user.notice root: VIT 19 2 1612 .0 . 874-370 5165-3626 2d 5d
    Oct 31 21:55:03 ROUTER user.notice root: VIT 11 2 1620 .0 . 919-372 5211-3670 2d 5d
    Oct 31 22:25:02 ROUTER user.notice root: VIT 91 3 1020 .0 . 1063-377 5356-3810 2d 5d
    Oct 31 22:55:02 ROUTER user.notice root: VIT 63 3 1572 .1 . 1152-380 5446-3897 2d 5d
    Oct 31 23:25:03 ROUTER user.notice root: VIT 28 3 1584 .0 . 1236-384 5531-3978 2d 5d
    Oct 31 23:55:02 ROUTER user.notice root: VIT 56 3 1592 .0 . 1251-385 5546-3992 2d 6d
    Nov  1 00:25:03 ROUTER user.notice root: VIT 46 2 1584 .0 . 1268-386 5563-4008 2d 6d
    Nov  1 00:55:02 ROUTER user.notice root: VIT 3 2 1592 .0 . 1271-387 5567-4011 2d 6d
    Nov  1 01:25:03 ROUTER user.notice root: VIT 7 2 1116 .0 . 1272-387 5567-4011 2d 6d
    Nov  1 01:55:02 ROUTER user.notice root: VIT 35 2 1592 .0 . 1280-388 5576-4019 2d 6d
    Nov  1 01:25:04 ROUTER user.notice root: VIT 10 2 1584 .0 . 1293-389 5589-4031 2d 6d
    Nov  1 01:55:02 ROUTER user.notice root: VIT 9 2 1588 .0 . 1302-390 5597-4038 2d 6d
    Nov  1 02:25:04 ROUTER user.notice root: VIT 9 1 1580 .0 . 1306-391 5602-4042 2d 6d
    Nov  1 02:55:02 ROUTER user.notice root: VIT 44 2 1588 .0 . 1314-391 5610-4050 2d 6d
    Nov  1 03:25:02 ROUTER user.notice root: VIT 19 2 1016 .0 . 1324-393 5620-4058 2d 6d
    Nov  1 03:55:02 ROUTER user.notice root: VIT 231 3 1568 .0 . 1343-398 5640-4073 2d 6d
    Nov  1 04:25:03 ROUTER user.notice root: VIT 210 2 1580 .0 . 1362-402 5659-4088 2d 6d
    Nov  1 04:55:02 ROUTER user.notice root: VIT 42 2 1588 .0 . 1390-405 5689-4114 2d 6d
    Nov  1 05:25:03 ROUTER user.notice root: VIT 26 2 1112 .0 . 1550-412 5849-4268 2d 6d
    Nov  1 05:55:02 ROUTER user.notice root: VIT 103 1 1588 .0 . 1575-413 5876-4293 2d 6d
    Nov  1 06:25:04 ROUTER user.notice root: VIT 176 1 1580 .1 . 1582-416 1587-2 2d 6d
    Nov  1 06:55:02 ROUTER user.notice root: VIT 184 1 1584 .1 . 1588-418 1593-6 2d 6d
    Nov  1 07:25:03 ROUTER user.notice root: VIT 9 1 1576 .0 . 1594-420 1600-11 2d 6d
    Nov  1 07:55:02 ROUTER user.notice root: VIT 48 1 1584 .0 . 1598-421 1605-15 2d 6d
    Nov  1 08:25:04 ROUTER user.notice root: VIT 3 0 1576 .0 . 1598-421 1605-15 2d 6d
    Nov  1 08:55:02 ROUTER user.notice root: VIT 0 0 1584 .0 . 1598-421 1605-15 2d 6d
    Nov  1 09:25:04 ROUTER user.notice root: VIT 3 0 1576 .0 . 1598-421 1605-15 2d 6d
    Nov  1 09:55:02 ROUTER user.notice root: VIT 0 0 1584 .0 . 1598-421 1605-15 2d 6d
    Nov  1 10:25:03 ROUTER user.notice root: VIT 2 0 1576 .0 . 1598-421 1605-15 2d 6d
    Nov  1 10:55:02 ROUTER user.notice root: VIT 61 1 1584 .0 . 1610-422 1617-25 2d 6d
    Nov  1 11:25:02 ROUTER user.notice root: VIT 7 1 1060 .0 . 1618-423 1625-33 2d 6d
    Nov  1 11:55:03 ROUTER user.notice root: VIT 14 1 1612 .0 . 1626-423 1634-41 2d 6d
    Nov  1 12:25:03 ROUTER user.notice root: VIT 34 1 1624 .0 . 1629-424 1636-43 2d 6d
    Nov  1 12:55:02 ROUTER user.notice root: VIT 27 1 1632 .0 . 1631-424 1638-45 2d 6d
    Nov  1 13:25:04 ROUTER user.notice root: VIT 29 1 1624 .0 . 1752-428 1760-163 2d 6d
    Nov  1 13:55:02 ROUTER user.notice root: VIT 41 1 1632 .0 . 1793-429 1801-203 2d 6d
    Nov  1 14:25:04 ROUTER user.notice root: VIT 41 2 1624 .0 . 1806-431 1814-214 2d 6d
    Nov  1 14:55:02 ROUTER user.notice root: VIT 45 3 1632 .0 . 1855-433 1864-262 2d 6d
    Nov  1 15:25:04 ROUTER user.notice root: VIT 93 4 1572 .0 . 2047-459 2058-430 2d 6d
    Nov  1 15:55:02 ROUTER user.notice root: VIT 61 3 1580 .0 . 2122-465 2134-500 2d 6d
    Nov  1 16:25:04 ROUTER user.notice root: VIT 15 3 1572 .0 . 2137-467 2150-513 2d 6d
    Nov  1 16:55:02 ROUTER user.notice root: VIT 69 3 1580 .0 . 2142-469 2155-516 2d 6d
    Nov  1 17:25:04 ROUTER user.notice root: VIT 81 3 1572 .0 . 2211-473 2225-582 2d 6d
    Nov  1 17:55:02 ROUTER user.notice root: VIT 49 3 1576 .0 . 2299-493 2313-651 3d 6d
    Nov  1 18:25:02 ROUTER user.notice root: VIT 172 3 1004 .0 . 2381-498 2397-729 3d 6d
    Nov  1 18:55:02 ROUTER user.notice root: VIT 195 3 1556 .1 . 2444-501 2460-789 3d 6d
    Nov  1 19:25:03 ROUTER user.notice root: VIT 193 3 1568 .0 . 2519-504 2536-862 3d 6d
    Nov  1 19:55:02 ROUTER user.notice root: VIT 198 3 1576 .0 . 2630-510 2647-968 3d 6d
    Nov  1 20:25:03 ROUTER user.notice root: VIT 276 4 1004 .0 . 2640-512 2659-977 3d 6d
    Nov  1 20:55:02 ROUTER user.notice root: VIT 266 4 1556 .0 . 2698-515 2716-1031 3d 6d
    Nov  1 21:25:04 ROUTER user.notice root: VIT 229 4 1568 .0 . 2775-518 2795-1107 3d 6d
    Nov  1 21:55:02 ROUTER user.notice root: VIT 81 4 1576 .0 . 2781-520 2800-1111 3d 6d
    Nov  1 22:25:02 ROUTER user.notice root: VIT 294 5 1004 .0 . 2801-525 2821-1126 3d 6d
    Nov  1 22:55:02 ROUTER user.notice root: VIT 261 5 1556 .0 . 2870-536 2892-1186 3d 7d
    Nov  1 23:25:04 ROUTER user.notice root: VIT 264 5 1568 .1 . 2914-549 2935-1216 3d 7d
    Nov  1 23:55:02 ROUTER user.notice root: VIT 151 5 1572 .0 . 2971-559 2994-1265 3d 7d
    Nov  2 00:25:04 ROUTER user.notice root: VIT 110 4 1564 .0 . 2999-565 3022-1287 3d 7d
    Nov  2 00:55:02 ROUTER user.notice root: VIT 20 4 1572 .0 . 3054-568 3077-1339 3d 7d
    Nov  2 01:25:03 ROUTER user.notice root: VIT 14 3 1564 .0 . 3060-569 3084-1345 3d 7d
    Nov  2 01:55:02 ROUTER user.notice root: VIT 35 3 1572 .0 . 3067-571 3092-1351 3d 7d
    Nov  2 02:25:03 ROUTER user.notice root: VIT 220 3 1564 .1 . 3227-576 3253-1507 3d 7d
    Nov  2 02:55:03 ROUTER user.notice root: VIT 235 3 1572 .0 . 3254-580 3281-1531 3d 7d
    Nov  2 03:25:02 ROUTER user.notice root: VIT 253 3 1000 .0 . 3362-585 3390-1635 3d 7d
    Nov  2 03:55:02 ROUTER user.notice root: VIT 21 2 1552 .0 . 3487-590 3516-1756 3d 7d
    Nov  2 04:25:02 ROUTER user.notice root: VIT 9 2 1000 .0 . 3576-593 3606-1843 3d 7d
    Nov  2 04:55:02 ROUTER user.notice root: VIT 6 1 1552 .0 . 3654-595 3684-1919 3d 7d
    Nov  2 05:25:03 ROUTER user.notice root: VIT 29 1 1564 .0 . 3792-600 3824-2054 3d 7d
    Nov  2 05:55:02 ROUTER user.notice root: VIT 3 1 1572 .0 . 3954-604 3987-2213 3d 7d
    Nov  2 06:25:03 ROUTER user.notice root: VIT 3 0 1468 .0 . 3975-605 4008-2233 3d 7d
    Nov  2 06:55:02 ROUTER user.notice root: VIT 1 0 1572 .0 . 3975-605 4008-2233 3d 7d
    Nov  2 07:25:02 ROUTER user.notice root: VIT 105 1 1000 .0 . 3983-605 4017-2242 3d 7d
    Nov  2 07:55:02 ROUTER user.notice root: VIT 225 1 1552 .0 . 4074-608 4109-2331 3d 7d
    Nov  2 08:25:04 ROUTER user.notice root: VIT 95 1 1564 .0 . 4075-608 4110-2332 3d 7d
    Nov  2 08:55:02 ROUTER user.notice root: VIT 8 1 1572 .0 . 4077-609 4112-2333 3d 7d
    Nov  2 09:25:04 ROUTER user.notice root: VIT 11 1 1564 .0 . 4098-623 4133-2340 3d 7d
    Nov  2 09:55:02 ROUTER user.notice root: VIT 9 1 1568 .0 . 4122-646 4157-2341 3d 7d
    Nov  2 10:25:03 ROUTER user.notice root: VIT 9 1 1560 .0 . 4124-647 4159-2342 3d 7d
    Nov  2 10:55:02 ROUTER user.notice root: VIT 60 2 1568 .0 . 4149-649 4184-2365 3d 7d
    Nov  2 11:25:03 ROUTER user.notice root: VIT 76 2 996 .0 . 4167-651 4203-2382 3d 7d
    Nov  2 11:55:02 ROUTER user.notice root: VIT 107 3 1548 .0 . 4178-652 4213-2391 3d 7d
    Nov  2 12:25:04 ROUTER user.notice root: VIT 24 2 1560 .0 . 4180-653 4215-2392 3d 7d
    Nov  2 12:55:02 ROUTER user.notice root: VIT 23 2 1568 .0 . 4181-654 4217-2393 3d 7d
    Nov  2 13:25:02 ROUTER user.notice root: VIT 39 2 1464 .0 . 4182-654 4217-2393 3d 7d
    Nov  2 13:55:02 ROUTER user.notice root: VIT 32 2 1564 .0 . 4185-655 4221-2395 3d 7d
    Nov  2 14:25:03 ROUTER user.notice root: VIT 58 3 1556 .0 . 4211-658 4247-2419 3d 7d
    Nov  2 14:55:03 ROUTER user.notice root: VIT 134 4 1564 .0 . 4340-668 4377-2539 3d 7d
    Nov  2 15:25:02 ROUTER user.notice root: VIT 124 3 992 .0 . 4397-674 4435-2591 3d 7d
    Nov  2 15:55:02 ROUTER user.notice root: VIT 85 3 1544 .1 . 4501-689 4540-2681 3d 7d
    Nov  2 15:59:13 ROUTER user.notice root: VIT 46 3 1436 .0 . 4530-691 4568-2707 3d 7d
    Nov  2 16:25:04 ROUTER user.notice root: VIT 396 3 988 .2 . 4644-698 4684-2816 3d 7d
    
     
  12. TexasFlood

    TexasFlood Network Guru Member

    Good info, what are you running to log that data?
     
  13. Planiwa

    Planiwa LI Guru Member

    It's a shell script to give a "Vital Statistics" snapshot.
    Run every 30 min by Scheduler.
     
  14. TexasFlood

    TexasFlood Network Guru Member

    That's what I suspected. I know how to get some of that out of /proc, but not sure how to get it all. Mind sharing? :biggrin:
     
  15. Planiwa

    Planiwa LI Guru Member

    Vital Statistics Script

    Here it is:

    Code:
    # Vital stats: Connections WiFiClients Free Load IFStates PPPTT-PPPUP WTT-WUP WANUptime SysUptime # Planiwa
    CON=$(cat /proc/net/ip_conntrack | wc -l)
    WLC=$(wl assoclist | wc -l)
    set -- $(free);F=$9
    
    set -- $(cat /proc/loadavg)
    LOADL=${1%.*}; LOADL=${LOADL#0}; LOADR=${1#*.}; LOADR=${LOADR#0};
    LOADR=$(((LOADR+5)/10)); case $LOADR in 10)LOADR=9;;esac; LOAD=$LOADL.$LOADR
    
    set -- $(ifconfig ppp0) $(ifconfig br0);U=${9#UP}.${46#UP};Y=""
    for X in ${30} ${34} ${67} ${71};do X=${X#*:}
    if [ ${#X} -le 3 ];then X=0;else X=${X%???};fi; Y="$Y $(((X+500)/1000))"
    done
    set -- $Y; Y="$(($1+$2))-$2 $(($3+$4))-$4"
    
    NOWSEC=$(date '+%s')
    WANSEC=$(date -r /var/lib/misc/wantime '+%s')
    BOOSEC=$(cat /proc/stat|grep btime); BOOSEC=${BOOSEC#* }
    case $WANSEC in ?|??) WANSEC=$BOOSEC;; esac
    BOOSEC=$((NOWSEC-BOOSEC))
    D=$((BOOSEC/86400));if [ $D -ge 1 ];then BOOTIME=${D}d;else
    H=$((BOOSEC/3600));if [ $H -ge 1 ];then BOOTIME=${H}h;else
    M=$((BOOSEC/60));if [ $M -ge 1 ];then BOOTIME=${M}m;else
    BOOTIME=${BOOSEC}s;fi;fi;fi
    WANSEC=$((NOWSEC-WANSEC))
    D=$((WANSEC/86400));if [ $D -ge 1 ];then WANTIME=${D}d;else
    H=$((WANSEC/3600));if [ $H -ge 1 ];then WANTIME=${H}h;else
    M=$((WANSEC/60));if [ $M -ge 1 ];then WANTIME=${M}m;else
    WANTIME=${WANSEC}s;fi;fi;fi
    #WANDATE=$(date -r /var/lib/misc/wantime '+%y%m%d.%H:%M')
    #BOODATE=$(cat /proc/stat|grep btime|awk '{print strftime("%m%d.%H:%M",$2)}')
    
    logger "VIT $CON $WLC $F $LOAD $U ${Y# } $WANTIME $BOOTIME"
    
     
  16. TexasFlood

    TexasFlood Network Guru Member

    Thanks, removed the pptp stuff since it doesn't apply to me and started running it via cron, seems to be working fine logging - connections, wifi clients, free memory, cpu load, WAN uptime and system uptime.
     
  17. Planiwa

    Planiwa LI Guru Member

    Ahem -- that' not PPTP, but PPP ToTal and PPP Up, as well as WiFi ToTal and -Up -- WAN and LAN traffic in MB. You might find it useful. :)

    But do keep in mind that the counters are reset at 4.3 GB (== 2^32).
     
  18. TexasFlood

    TexasFlood Network Guru Member

    Quite right, I stand corrected, and will have to take a look at the other counters.

    Thanks again.

    * update: I went back to the original script, tried just replacing $(ifconfig ppp0) with $(ifconfig vlan1) to better fit my cable modem setup. As I said, the rest of it works fine but this didn't as the output looked like:
    Code:
    VIT 35 4 7644 .0 Mask:255.255.248.0.Mask:255.255.255.0 0-0 0-0 10h 10h
    Have to look at it later, work to do now.
     
  19. Planiwa

    Planiwa LI Guru Member

    Ah. Thanks for that. Much appreciated. I've changed that part to make it a little more robust.

    Code:
    # Vital stats: Connections WiFiClients Free Load IFStates WANTT-WANUP WiTT-WiUP WANUptime SysUptime # Planiwa
    CON=$(cat /proc/net/ip_conntrack | wc -l)
    WLC=$(wl assoclist | wc -l)
    set -- $(free);F=$9
    
    set -- $(cat /proc/loadavg)
    LOADL=${1%.*}; LOADL=${LOADL#0}; LOADR=${1#*.}; LOADR=${LOADR#0};
    LOADR=$(((LOADR+5)/10)); case $LOADR in 10)LOADR=9;;esac; LOAD=$LOADL.$LOADR
    
    X="";for IF in vlan1 br0;do set -- $(ifconfig $IF); shift $(($#-8)); X="$X $2 $6"; done
    Y=""; set -- $X; for X in $*;do
    X=${X#*:}; if [ ${#X} -le 3 ];then X=0;else X=${X%???};fi; Y="$Y $(((X+500)/1000))"
    done
    set -- $Y; Y="$(($1+$2))-$2 $(($3+$4))-$4"
    
    NOWSEC=$(date '+%s')
    WANSEC=$(date -r /var/lib/misc/wantime '+%s')
    BOOSEC=$(cat /proc/stat|grep btime); BOOSEC=${BOOSEC#* }
    case $WANSEC in ?|??) WANSEC=$BOOSEC;; esac
    BOOSEC=$((NOWSEC-BOOSEC))
    D=$((BOOSEC/86400));if [ $D -ge 1 ];then BOOTIME=${D}d;else
    H=$((BOOSEC/3600));if [ $H -ge 1 ];then BOOTIME=${H}h;else
    M=$((BOOSEC/60));if [ $M -ge 1 ];then BOOTIME=${M}m;else
    BOOTIME=${BOOSEC}s;fi;fi;fi
    WANSEC=$((NOWSEC-WANSEC))
    D=$((WANSEC/86400));if [ $D -ge 1 ];then WANTIME=${D}d;else
    H=$((WANSEC/3600));if [ $H -ge 1 ];then WANTIME=${H}h;else
    M=$((WANSEC/60));if [ $M -ge 1 ];then WANTIME=${M}m;else
    WANTIME=${WANSEC}s;fi;fi;fi
    #WANDATE=$(date -r /var/lib/misc/wantime '+%y%m%d.%H:%M')
    #BOODATE=$(cat /proc/stat|grep btime|awk '{print strftime("%m%d.%H:%M",$2)}')
    
    logger "VIT $CON $WLC $F $LOAD ${Y# } $WANTIME $BOOTIME"
    
     
  20. TexasFlood

    TexasFlood Network Guru Member

    I just rebooted so need a little time to let the stats build up but looking good so far, no script runtime or output format errors.

    Thanks again!
     
  21. jan.n

    jan.n Addicted to LI Member

    Just as I was about to ask how to do this 'cause I'm on cable :thumbup:
    Thank you bigtime!
     
  22. Planiwa

    Planiwa LI Guru Member

    This is the best. :) It defaults to vlan1 and br0, but you can specify any set of interfaces, e.g.:

    vit ppp0 vlan1 br0 eth0


    Code:
    # Vital stats: Connections WiFiClients Free Load WANTT-WANUP WiTT-WiUP WANUptime SysUptime # Planiwa 2009-11-03
    
    case $# in
    0) INTERFACES="vlan1 br0";;
    *) INTERFACES="$*";;
    esac
    
    CON=$(cat /proc/net/ip_conntrack | wc -l)
    WLC=$(wl assoclist | wc -l)
    set -- $(free);F=$9
    
    set -- $(cat /proc/loadavg)
    LOADL=${1%.*}; LOADL=${LOADL#0}; LOADR=${1#*.}; LOADR=${LOADR#0};
    LOADR=$(((LOADR+5)/10)); case $LOADR in 10)LOADR=9;;esac; LOAD=$LOADL.$LOADR
    
    X="";Y="";Z=""; for IF in $INTERFACES;do
      set -- $(ifconfig $IF)                  ### Beware: counters are reset at 4.3 GB (== 2^32) ###
      case $# in
      0) Z="$Z $IF:Down";;
      *) shift $(($#-8)); X="$X $2 $6";;
      esac
    done
    set -- $X; for X in $*;do
      X=${X#*:}; if [ ${#X} -le 3 ];then X=0;else X=${X%???};fi; Y="$Y $(((X+500)/1000))"
    done
    set -- $Y
    while [ $# -ge 2 ];do
      Z="$Z $(($1+$2))-$2"
      shift 2
    done
    
    NOWSEC=$(date '+%s')
    WANSEC=$(date -r /var/lib/misc/wantime '+%s')
    BOOSEC=$(cat /proc/stat|grep btime); BOOSEC=${BOOSEC#* }
    case $WANSEC in ?|??) WANSEC=$BOOSEC;; esac
    BOOSEC=$((NOWSEC-BOOSEC))
    D=$((BOOSEC/86400));if [ $D -ge 1 ];then BOOTIME=${D}d;else
    H=$((BOOSEC/3600));if [ $H -ge 1 ];then BOOTIME=${H}h;else
    M=$((BOOSEC/60));if [ $M -ge 1 ];then BOOTIME=${M}m;else
    BOOTIME=${BOOSEC}s;fi;fi;fi
    WANSEC=$((NOWSEC-WANSEC))
    D=$((WANSEC/86400));if [ $D -ge 1 ];then WANTIME=${D}d;else
    H=$((WANSEC/3600));if [ $H -ge 1 ];then WANTIME=${H}h;else
    M=$((WANSEC/60));if [ $M -ge 1 ];then WANTIME=${M}m;else
    WANTIME=${WANSEC}s;fi;fi;fi
    #WANDATE=$(date -r /var/lib/misc/wantime '+%y%m%d.%H:%M')
    #BOODATE=$(cat /proc/stat|grep btime|awk '{print strftime("%m%d.%H:%M",$2)}')
    
    logger "VIT $CON $WLC $F $LOAD ${Z# } $WANTIME $BOOTIME"
    
     
  23. TexasFlood

    TexasFlood Network Guru Member

    Installed this version and it's working fine. However I noticed that if I specify interfaces eth0 or eth1, they both just report 0s. Perhaps it's something with the format of the output of ifconfig for those interfaces including an extra line regarding Interrupts throwing off the script, not sure. Just FYI, as it doesn't impact the default way I'm running it.
     
  24. Planiwa

    Planiwa LI Guru Member

    Hm. Sorry about that. This one should take care of that. ...

    Code:
    # Vital stats: Connections WiFiClients Free Load WANTT-WANUP WiTT-WiUP WANUptime SysUptime # Planiwa 2009-11-03.1
    
    case $# in
    0) INTERFACES="vlan1 br0";;
    *) INTERFACES="$*";;
    esac
    
    CON=$(cat /proc/net/ip_conntrack | wc -l)
    WLC=$(wl assoclist | wc -l)
    set -- $(free);F=$9
    
    set -- $(cat /proc/loadavg)
    LOADL=${1%.*}; LOADL=${LOADL#0}; LOADR=${1#*.}; LOADR=${LOADR#0};
    LOADR=$(((LOADR+5)/10)); case $LOADR in 10)LOADR=9;;esac; LOAD=$LOADL.$LOADR
    
    X="";Y="";Z=""; for IF in $INTERFACES;do
      set -- $(ifconfig $IF |grep 'RX bytes:') ### Beware: counters are reset at 4.3 GB (== 2^32) ###
      case $# in
      0) Z="$Z $IF:Down";;
      *) X="$X $2 $6";;
      esac
    done
    set -- $X; for X in $*;do
      X=${X#*:}; if [ ${#X} -le 3 ];then X=0;else X=${X%???};fi; Y="$Y $(((X+500)/1000))"
    done
    set -- $Y
    while [ $# -ge 2 ];do
      Z="$Z $(($1+$2))-$2"
      shift 2
    done
    
    NOWSEC=$(date '+%s')
    WANSEC=$(date -r /var/lib/misc/wantime '+%s')
    BOOSEC=$(cat /proc/stat|grep btime); BOOSEC=${BOOSEC#* }
    case $WANSEC in ?|??) WANSEC=$BOOSEC;; esac
    BOOSEC=$((NOWSEC-BOOSEC))
    D=$((BOOSEC/86400));if [ $D -ge 1 ];then BOOTIME=${D}d;else
    H=$((BOOSEC/3600));if [ $H -ge 1 ];then BOOTIME=${H}h;else
    M=$((BOOSEC/60));if [ $M -ge 1 ];then BOOTIME=${M}m;else
    BOOTIME=${BOOSEC}s;fi;fi;fi
    WANSEC=$((NOWSEC-WANSEC))
    D=$((WANSEC/86400));if [ $D -ge 1 ];then WANTIME=${D}d;else
    H=$((WANSEC/3600));if [ $H -ge 1 ];then WANTIME=${H}h;else
    M=$((WANSEC/60));if [ $M -ge 1 ];then WANTIME=${M}m;else
    WANTIME=${WANSEC}s;fi;fi;fi
    #WANDATE=$(date -r /var/lib/misc/wantime '+%y%m%d.%H:%M')
    #BOODATE=$(cat /proc/stat|grep btime|awk '{print strftime("%m%d.%H:%M",$2)}')
    
    logger "VIT $CON $WLC $F $LOAD ${Z# } $WANTIME $BOOTIME"
    
     
  25. TexasFlood

    TexasFlood Network Guru Member

    Cool. Try as I might, can't find anything else to complain about, :smile:

    FYI for others using this, the memory being tracked here is without counting cached memory as free memory. As both free memory and cached memory are available in /proc/meminfo, looks you can derive the same figure Tomato tracks when counting cached memory as free with (MemFree+Cached)/1024, if you really want it.

    Planiwa, not intended as a complaint, merely an FYI comment.

    Thanks a lot
     
  26. Planiwa

    Planiwa LI Guru Member

    Right. Yesterday I posted IDLE, which displays the Cached memory if MemFree is low. Might want to check it out. :)

    Also, we should keep in mind that running a shell script command will reduce free memory (while the command is running).

    I've made a couple of changes to vit:

    1. Now displays Cached memory too,
    2. Displays to Terminal when run interactively, to Syslog when run by Scheduler.

    Code:
    # Vital stats: Connections WiFiClients Free+Cached Load WANTT-WANUP WiTT-WiUP WANUptime SysUptime # Planiwa 2009-11-04
    
    case $# in
    0) INTERFACES="vlan1 br0";;
    *) INTERFACES="$*";;
    esac
    
    CON=$(cat /proc/net/ip_conntrack | wc -l)
    WLC=$(wl assoclist | wc -l)
    set -- $(cat /proc/meminfo); F="${22}+${31}"
    
    set -- $(cat /proc/loadavg)
    LOADL=${1%.*}; LOADL=${LOADL#0}; LOADR=${1#*.}; LOADR=${LOADR#0};
    LOADR=$(((LOADR+5)/10)); case $LOADR in 10)LOADR=9;;esac; LOAD=$LOADL.$LOADR
    
    X="";Y="";Z=""; for IF in $INTERFACES;do
      set -- $(ifconfig $IF |grep 'RX bytes:') ### Beware: counters are reset at 4.3 GB (== 2^32) ###
      case $# in
      0) Z="$Z $IF:Down";;
      *) X="$X $2 $6";;
      esac
    done
    set -- $X; for X in $*;do
      X=${X#*:}; if [ ${#X} -le 3 ];then X=0;else X=${X%???};fi; Y="$Y $(((X+500)/1000))"
    done
    set -- $Y
    while [ $# -ge 2 ];do
      Z="$Z $(($1+$2))-$2"
      shift 2
    done
    
    NOWSEC=$(date '+%s')
    WANSEC=$(date -r /var/lib/misc/wantime '+%s')
    BOOSEC=$(cat /proc/stat|grep btime); BOOSEC=${BOOSEC#* }
    case $WANSEC in ?|??) WANSEC=$BOOSEC;; esac
    BOOSEC=$((NOWSEC-BOOSEC))
    D=$((BOOSEC/86400));if [ $D -ge 1 ];then BOOTIME=${D}d;else
    H=$((BOOSEC/3600));if [ $H -ge 1 ];then BOOTIME=${H}h;else
    M=$((BOOSEC/60));if [ $M -ge 1 ];then BOOTIME=${M}m;else
    BOOTIME=${BOOSEC}s;fi;fi;fi
    WANSEC=$((NOWSEC-WANSEC))
    D=$((WANSEC/86400));if [ $D -ge 1 ];then WANTIME=${D}d;else
    H=$((WANSEC/3600));if [ $H -ge 1 ];then WANTIME=${H}h;else
    M=$((WANSEC/60));if [ $M -ge 1 ];then WANTIME=${M}m;else
    WANTIME=${WANSEC}s;fi;fi;fi
    #WANDATE=$(date -r /var/lib/misc/wantime '+%y%m%d.%H:%M')
    #BOODATE=$(cat /proc/stat|grep btime|awk '{print strftime("%m%d.%H:%M",$2)}')
    
    case $PATH in            
    *root:)  echo   "VIT $CON $WLC $F $LOAD ${Z# } $WANTIME $BOOTIME" ;; # Interactive Terminal Shell
    *)       logger "VIT $CON $WLC $F $LOAD ${Z# } $WANTIME $BOOTIME" ;; # Scheduler / Script
    esac                                                             
    
     
  27. TexasFlood

    TexasFlood Network Guru Member

    Yes, I saw your IDLE script but haven't had a chance to look at it yet. Thanks for that and for the vit modifications, you keep improving it. The script test to display to terminal when run interactively or to syslog when run by scheduler didn't work on my current (thor) build as the path is set differently, but I adjusted it to work with the path in my version.
     
  28. Planiwa

    Planiwa LI Guru Member

    Excellent. I did the same. Am just waiting for the next Scheduler run before posting. ... yes, it works.

    Code:
    # Vital stats: Connections WiFiClients Free+Cached Load WANTT-WANUP WiTT-WiUP WANUptime SysUptime # Planiwa 2009-11-04.3
    
    case $# in
    0) INTERFACES="vlan1 br0";;
    *) INTERFACES="$*";;
    esac
    
    CON=$(cat /proc/net/ip_conntrack | wc -l)
    WLC=$(wl assoclist | wc -l)
    set -- $(cat /proc/meminfo); F="${22}+${31}"
    
    set -- $(cat /proc/loadavg)
    LOADL=${1%.*}; LOADL=${LOADL#0}; LOADR=${1#*.}; LOADR=${LOADR#0};
    LOADR=$(((LOADR+5)/10)); case $LOADR in 10)LOADR=9;;esac; LOAD=$LOADL.$LOADR
    
    X="";Y="";Z=""; for IF in $INTERFACES;do
      set -- $(ifconfig $IF |grep 'RX bytes:') ### Beware: counters are reset at 4.3 GB (== 2^32) ###
      case $# in
      0) Z="$Z $IF:Down";;
      *) X="$X $2 $6";;
      esac
    done
    set -- $X; for X in $*;do
      X=${X#*:}; if [ ${#X} -le 3 ];then X=0;else X=${X%???};fi; Y="$Y $(((X+500)/1000))"
    done
    set -- $Y
    while [ $# -ge 2 ];do
      Z="$Z $(($1+$2))-$2"
      shift 2
    done
    
    NOWSEC=$(date '+%s')
    WANSEC=$(date -r /var/lib/misc/wantime '+%s')
    BOOSEC=$(cat /proc/stat|grep btime); BOOSEC=${BOOSEC#* }
    case $WANSEC in ?|??) WANSEC=$BOOSEC;; esac
    BOOSEC=$((NOWSEC-BOOSEC))
    D=$((BOOSEC/86400));if [ $D -ge 1 ];then BOOTIME=${D}d;else
    H=$((BOOSEC/3600));if [ $H -ge 1 ];then BOOTIME=${H}h;else
    M=$((BOOSEC/60));if [ $M -ge 1 ];then BOOTIME=${M}m;else
    BOOTIME=${BOOSEC}s;fi;fi;fi
    WANSEC=$((NOWSEC-WANSEC))
    D=$((WANSEC/86400));if [ $D -ge 1 ];then WANTIME=${D}d;else
    H=$((WANSEC/3600));if [ $H -ge 1 ];then WANTIME=${H}h;else
    M=$((WANSEC/60));if [ $M -ge 1 ];then WANTIME=${M}m;else
    WANTIME=${WANSEC}s;fi;fi;fi
    #WANDATE=$(date -r /var/lib/misc/wantime '+%y%m%d.%H:%M')
    #BOODATE=$(cat /proc/stat|grep btime|awk '{print strftime("%m%d.%H:%M",$2)}')
    
    case "$PWD" in            
    /tmp) logger "VIT $CON $WLC $F $LOAD ${Z# } $WANTIME $BOOTIME" ;; # Scheduler / Script
    *)    echo   "VIT $CON $WLC $F $LOAD ${Z# } $WANTIME $BOOTIME" ;; # Interactive Terminal Shell
    esac                                                             
    
    
     
  29. TexasFlood

    TexasFlood Network Guru Member

    Typo, leftover diagnostic step? I just deleted that line.
     
  30. Planiwa

    Planiwa LI Guru Member

    Good catch! Thanks :)
     
  31. rhester72

    rhester72 Network Guru Member

    One other small change I made:

    Code:
    case "$PWD" in            
    /tmp) logger "VIT $CON $WLC $F $LOAD ${Z# } $WANTIME $BOOTIME" ;; # Scheduler / Script
    *)    echo   "VIT $CON $WLC $F $LOAD ${Z# } $WANTIME $BOOTIME" ;; # Interactive Terminal Shell
    esac
    
    becomes

    Code:
    case `ps | grep ${PPID} | grep -c "/bin/sh /tmp/sch_c[1-3]_cmd.sh"` in
    0) echo              "VIT $CON $WLC $F $LOAD ${Z# } $WANTIME $BOOTIME" ;; # Interactive Terminal Shell
    1) logger -t VIT -p info "$CON $WLC $F $LOAD ${Z# } $WANTIME $BOOTIME" ;; # Scheduler / Script
    esac
    
     
  32. Planiwa

    Planiwa LI Guru Member

    Incorporated those good ideas (with slight changes), and also reversed display sequence of Users and Connections:

    Code:
    # Vital stats: WiFiClients Connections Free+Cached Load WANTT-WANUP WiTT-WiUP WANUptime SysUptime # Planiwa 2009-11-05
    
    case $# in
    0) INTERFACES="vlan1 br0";;
    *) INTERFACES="$*";;
    esac
    
    CON=$(cat /proc/net/ip_conntrack | wc -l)
    WLC=$(wl assoclist | wc -l)
    set -- $(cat /proc/meminfo); F="${22}+${31}"
    
    set -- $(cat /proc/loadavg)
    LOADL=${1%.*}; LOADL=${LOADL#0}; LOADR=${1#*.}; LOADR=${LOADR#0};
    LOADR=$(((LOADR+5)/10)); case $LOADR in 10)LOADR=9;;esac; LOAD=$LOADL.$LOADR
    
    X="";Y="";Z=""; for IF in $INTERFACES;do
      set -- $(ifconfig $IF |grep 'RX bytes:') ### Beware: counters are reset at 4.3 GB (== 2^32) ###
      case $# in
      0) Z="$Z $IF:Down";;
      *) X="$X $2 $6";;
      esac
    done
    set -- $X; for X in $*;do
      X=${X#*:}; if [ ${#X} -le 3 ];then X=0;else X=${X%???};fi; Y="$Y $(((X+500)/1000))"
    done
    set -- $Y
    while [ $# -ge 2 ];do
      Z="$Z $(($1+$2))-$2"
      shift 2
    done
    
    NOWSEC=$(date '+%s')
    WANSEC=$(date -r /var/lib/misc/wantime '+%s')
    BOOSEC=$(cat /proc/stat|grep btime); BOOSEC=${BOOSEC#* }
    case $WANSEC in ?|??) WANSEC=$BOOSEC;; esac
    BOOSEC=$((NOWSEC-BOOSEC))
    D=$((BOOSEC/86400));if [ $D -ge 1 ];then BOOTIME=${D}d;else
    H=$((BOOSEC/3600));if [ $H -ge 1 ];then BOOTIME=${H}h;else
    M=$((BOOSEC/60));if [ $M -ge 1 ];then BOOTIME=${M}m;else
    BOOTIME=${BOOSEC}s;fi;fi;fi
    WANSEC=$((NOWSEC-WANSEC))
    D=$((WANSEC/86400));if [ $D -ge 1 ];then WANTIME=${D}d;else
    H=$((WANSEC/3600));if [ $H -ge 1 ];then WANTIME=${H}h;else
    M=$((WANSEC/60));if [ $M -ge 1 ];then WANTIME=${M}m;else
    WANTIME=${WANSEC}s;fi;fi;fi
    #WANDATE=$(date -r /var/lib/misc/wantime '+%y%m%d.%H:%M')
    #BOODATE=$(cat /proc/stat|grep btime|awk '{print strftime("%m%d.%H:%M",$2)}')
    
    case $(ps | grep ${PPID} | grep -c '/bin/sh /tmp/sc[hr].*\.sh') in
    0) echo             "VIT: $WLC $CON $F $LOAD ${Z# } $WANTIME $BOOTIME" ;; # Interactive Terminal Shell
    *) logger -p info -t VIT "$WLC $CON $F $LOAD ${Z# } $WANTIME $BOOTIME" ;; # Scheduler / Script
    esac
    
    
     
  33. rhester72

    rhester72 Network Guru Member

    Using ps->grep pipe seems like a tiny bit of overkill - have been trying to make it a bit more efficient using /proc/<PID>/cmdline but it would seem that spaces in the command line are stripped (!?). Thoughts?

    Rodney
     
  34. Planiwa

    Planiwa LI Guru Member

    This is much better. :)

    I've added the Process Count -- while there is no memory leak, there is a process leak, i.e. zombie-like shells that live on when processes are killed, and trying to kill them just transforms them ...

    Code:
    # Vital stats: WiFiClients Connections Free+Cached Load Processes WANTT-WANUP WiTT-WiUP WANUptime SysUptime # Planiwa 2009-11-05.1
    
    case $# in
    0) INTERFACES="vlan1 br0";;
    *) INTERFACES="$*";;
    esac
    
    CON=$(cat /proc/net/ip_conntrack | wc -l)
    WLC=$(wl assoclist | wc -l)
    set -- $(cat /proc/meminfo); F="${22}+${31}"
    
    set -- $(cat /proc/loadavg)
    P=$4
    LOADL=${1%.*}; LOADL=${LOADL#0}; LOADR=${1#*.}; LOADR=${LOADR#0};
    LOADR=$(((LOADR+5)/10)); case $LOADR in 10)LOADR=9;;esac; LOAD=$LOADL.$LOADR
    
    X="";Y="";Z=""; for IF in $INTERFACES;do
      set -- $(ifconfig $IF |grep 'RX bytes:') ### Beware: counters are reset at 4.3 GB (== 2^32) ###
      case $# in
      0) Z="$Z $IF:Down";;
      *) X="$X $2 $6";;
      esac
    done
    set -- $X; for X in $*;do
      X=${X#*:}; if [ ${#X} -le 3 ];then X=0;else X=${X%???};fi; Y="$Y $(((X+500)/1000))"
    done
    set -- $Y
    while [ $# -ge 2 ];do
      Z="$Z $(($1+$2))-$2"
      shift 2
    done
    
    NOWSEC=$(date '+%s')
    WANSEC=$(date -r /var/lib/misc/wantime '+%s')
    BOOSEC=$(cat /proc/stat|grep btime); BOOSEC=${BOOSEC#* }
    case $WANSEC in ?|??) WANSEC=$BOOSEC;; esac
    BOOSEC=$((NOWSEC-BOOSEC))
    D=$((BOOSEC/86400));if [ $D -ge 1 ];then BOOTIME=${D}d;else
    H=$((BOOSEC/3600));if [ $H -ge 1 ];then BOOTIME=${H}h;else
    M=$((BOOSEC/60));if [ $M -ge 1 ];then BOOTIME=${M}m;else
    BOOTIME=${BOOSEC}s;fi;fi;fi
    WANSEC=$((NOWSEC-WANSEC))
    D=$((WANSEC/86400));if [ $D -ge 1 ];then WANTIME=${D}d;else
    H=$((WANSEC/3600));if [ $H -ge 1 ];then WANTIME=${H}h;else
    M=$((WANSEC/60));if [ $M -ge 1 ];then WANTIME=${M}m;else
    WANTIME=${WANSEC}s;fi;fi;fi
    #WANDATE=$(date -r /var/lib/misc/wantime '+%y%m%d.%H:%M')
    #BOODATE=$(cat /proc/stat|grep btime|awk '{print strftime("%m%d.%H:%M",$2)}')
    
    case "$(cat /proc/$PPID/cmdline)" in
    */tmp/sc[hr]*.sh) logger -p info -t VIT "$WLC $CON $F $LOAD $P ${Z# } $WANTIME $BOOTIME" ;; # Scheduler / Adm Script
    *)                echo             "VIT: $WLC $CON $F $LOAD $P ${Z# } $WANTIME $BOOTIME" ;; # Interactive Shell
    esac
    
     
  35. TexasFlood

    TexasFlood Network Guru Member

    I'll add in the process count but since I run this from cron, think I'll stick with the earlier method of checking whether it's being run from /tmp to determine if it's interactive, works better for me. If I "cat /proc/$PPID/cmdline" from cron or from interactive, both return "dropbear-p22-a". Maybe I should switch over to a custom script, hmm, save me space in my init tab which is getting pretty full, have to mull that over. OR I can just copy the script from a cifs share. Too many options for the indecisive, :grin:
     

Share This Page