태그 보관물: network-manager

network-manager

터미널에서 모바일 광대역을 활성화 / 비활성화하는 방법은 무엇입니까? 후 수신 된 데이터가 20KB 미만인

Natty Narwhal에서 ZTE USB 모뎀을 사용합니다. 모든 것이 잘 작동하지만 때로는 연결이 끊어집니다. 모바일 광대역 연결이 끊어 졌거나 5 초 동안 연결 한 후 수신 된 데이터가 20KB 미만인 경우 모바일 광대역을 다시 연결하는 셸 스크립트를 작성하려고합니다.

내 질문은 모바일 광대역을 활성화 / 비활성화하는 방법입니다. 수신 한 데이터를 확인하는 방법은 무엇입니까? 네트워크 서비스를 활성화 / 비활성화하는 방법은 무엇입니까?

참고 : 터미널 명령 전용
또는 스크립트를 작성할 수 있다면 매우 감사하겠습니다.



답변

터미널 창을 열고 다음을 입력하십시오.

sudo gedit /etc/init.d/mobile-broadband-connect

그런 다음 복사하여 붙여 넣습니다 (필요에 따라 변경).

참고 : 를 교체 <Your Mobile Broadband Connection Name Here>연결의 이름으로.

#!/bin/bash

case "$1" in
start)
      echo "Starting Mobile Broadband Connection."
      while true; do
        # testing...to see if gsm is on the list of active devices
        LC_ALL=C nmcli -t -f TYPE,STATE dev | grep -q "^gsm:disconnected$"
        if [ $? -eq 0 ]; then
            break
        else
         # not connected, sleeping for a second
            sleep 1
        fi
      done
      # now once GSM modem shows up, run these commands
      nmcli -t nm wwan on
      nmcli -t con up id <Your Mobile Broadband Connection Name Here>
;;
stop)
      echo "Stopping Mobile Broadband Connection."
      nmcli -t con down id <Your Mobile Broadband Connection Name Here>
      nmcli -t nm wwan off
;;
status)
      # Check to see if the process is running with Network Manager dev status
      nmcli -p dev
;;

*)
      echo "Mobile Broadband Startup Service"
      echo $"Usage: $0 {start|stop|status}"
      exit 1
esac
exit 0

이 파일의 실행 권한을 변경하십시오.

sudo chmod +x /etc/init.d/mobile-broadband-connect

이 스크립트를 실행하려면 서비스가 있습니다.

sudo update-rc.d mobile-broadband-connect defaults

스크립트는 시스템 시작 서비스로 등록되므로 다음을 사용하여 스크립트의 시작, 중지 또는 상태를 확인할 수 있습니다.

sudo service mobile-broadband-connect start

sudo service mobile-broadband-connect stop

sudo service mobile-broadband-connect status

설치 및 자동 연결을 완료하려면 재부팅하십시오.

  • 시스템을 재부팅하여 설치를 완료하십시오.
  • 재부팅 후 USB 장치가 활성화되기까지 최대 60 초가 걸립니다.
  • 활성화되면-모바일 광대역 연결이 활성화되고 자동 연결됩니다.

완료 …


답변

나는 다음과 같이 쉘 스크립트를 Startup Applications만들고 그것을 넣었고 그것은 매력처럼 작동한다! 나는 이것에 만족하지만 당신이 더 나아질 수 있다면 나는 매우 감사 할 것입니다.

#!/bin/bash

while true; do
    LC_ALL=C nmcli -t -f TYPE,STATE dev | grep -q "^gsm:disconnected$"
    if [ $? -eq 0 ]; then
        #jdownloader is still in the download status so stop it because
        #internet is disconnected and jdownloader won't resume download
        #when connected again
        #jdownloader --stop-download
        #sometimes I can not get connected after disconnection when
        #I click on <name of the network connection>. I have to disable
        #and enable Mobile Broadband
        nmcli -t nm wwan off
        sleep 1
        nmcli -t nm wwan on
        sleep 1
        nmcli -t con up id "Tata Docomo Internet"
        #wait approximately 15 sec to get connected
        #if anyone can add better command to check for it just comment it :-p
        sleep 15
        #now connected to internet so start download
        #jdownloader --start-download
    fi
    #it does not worth keep it checking every millisecond.
    #my connection will be reestablished within 5-15 seconds
    sleep 2
    #if anyone can code it better please feel free to comment
    #TO-DO:: check for data received. if data < 15 KB after 20 seconds of connection
    #reconnect mobile broadband connection
done

답변

#!/bin/sh
echo "Starting Mobile Broadband Connection. Tej"
      while true; do
        # testing...to see if gsm is on the list of active devices
        LC_ALL=C nmcli -t -f TYPE,STATE dev | grep -q "^gsm:disconnected$"
        if [ $? -eq 0 ]; then
            break
        else
         # not connected, sleeping for a second
            sleep 1
        fi
      done
      # now once GSM modem shows up, run these commands

  while true; do
  # Enable Mobile Broadband
nmcli -t nm wwan on

  # Connect to network
nmcli -t con up id "BSNL/CellOne New GPRS/3G 1"

  # Check status if connected or not
nmcli -f device,state -t dev | grep ttyACM0 | awk -F':' '{print $2}' | { read status; }

echo $status;

if [$status == "connected"]; then
    break
else
     # not connected, sleeping for a second
    nmcli -t nm wwan off
            sleep 1
 fi
  done

답변