raspberry pi,脚本中的apt-get update不起作用

时间:2015-09-04 15:36:52

标签: bash raspberry-pi raspbian

当我跑步时:

sudo apt-get update
sudo apt-get upgrade
从命令行

,它可以工作。

如果我把相同的行放在一个脚本文件maintain.script:

echo UPDATING SYSTEM SOFTWARE – UPDATE
sudo apt-get update
echo UPDATING SYSTEM SOFTWARE – UPGRADE
sudo apt-get upgrade

并运行:

sudo ./maintain.sh

我收到错误:

E: Invalid operation update
E: Invalid operation upgrade

我已将脚本标记为可执行文件。

在FSQ评论后更新

这是脚本文件:

#!/bin/bash
echo "UPDATING SYSTEM SOFTWARE – UPDATE"
apt-get update
echo "UPDATING SYSTEM SOFTWARE – UPGRADE"
apt-get upgrade
echo "UPDATING SYSTEM SOFTWARE – DISTRIBUTION"
apt-get dist-upgrade
echo "REMOVING APPLICATION ORPHANS"
apt-get autoremove –purge
echo "UPDATING FIRMWARE"
rpi-update

这是命令:

pi@raspberrypi2 ~/projects $ sudo ./maintain.sh

结果如下:

: not foundsh: 1: ./maintain.sh: #!/bin/bash
UPDATING SYSTEM SOFTWARE – UPDATE
E: Invalid operation update
UPDATING SYSTEM SOFTWARE – UPGRADE
E: Invalid operation upgrade
UPDATING SYSTEM SOFTWARE – DISTRIBUTION
E: Invalid operation dist-upgrade
REMOVING APPLICATION ORPHANS
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package –purge
UPDATING FIRMWARE
: not foundsh: 11: ./maintain.sh: rpi-update

2 个答案:

答案 0 :(得分:6)

这是一个文件格式问题。我使用Windows记事本编辑文件夹共享上的文件,它使用不同的\ r \ n到Linux。

以下是更正我的脚本文件的命令:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import wx.lib.scrolledpanel
from random import randrange
class GUI(wx.Frame):

    def __init__(self, parent, id, title):
        screenWidth = 800
        screenHeight = 450
        screenSize = (screenWidth, screenHeight)
        wx.Frame.__init__(self, None, id, title, size=screenSize)
        self.locationFont = locationFont = wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD)
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer = sizer = wx.BoxSizer(wx.VERTICAL)
        self.panel = panel = wx.lib.scrolledpanel.ScrolledPanel(self, -1, style=wx.SIMPLE_BORDER)
        panel.SetupScrolling()
        panel.SetBackgroundColour('#FFFFFF')
        panel.SetSizer(sizer)
        mainSizer.Add(panel, 15, wx.EXPAND|wx.ALL)
        self.SetSizer(mainSizer)
        self.text_labels = []  # Stores the labels where server data is displayed
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
        self.timer.Start(5000)

    def OnNewLabels(self, labels):
        locations = labels
        print locations
        if len(self.text_labels) < len(labels):
            new_labels_needed = len(labels) - len(self.text_labels) 
            label = "(no data)"
            for i in range(new_labels_needed):
                sPanels = wx.Panel(self.panel)
                text = wx.StaticText(sPanels, -1, label)
                text.SetFont(self.locationFont)
                text.SetForegroundColour('#0101DF')
                self.sizer.Add(sPanels, 0, wx.ALL, 5)
                self.sizer.Add(wx.StaticLine(self.panel), 0, wx.ALL|wx.EXPAND, 0)
                self.text_labels.append(text)
            self.sizer.Layout()
        k = 0
        for label in locations:
            self.text_labels[k].SetLabel(str(label))
            k=k+1
        if len(self.text_labels) > len(labels):
            labels_not_needed = len(self.text_labels) - len(labels)
            for i in range(labels_not_needed):
                self.text_labels[k].SetLabel("-")
                k+=1

    def OnTimer(self, evt):
        # get the info from the server
        mylist =[]
        i = randrange(10)
        for k in range(1,i+1):
            mylist.append(randrange(10))
        self.OnNewLabels(mylist)

if __name__=='__main__':
    app = wx.App()
    frame = GUI(parent=None, id=-1, title="Test")
    frame.Show()
    app.MainLoop()

这是我用来处理文件夹中所有脚本文件的脚本文件,并确保它们是可执行的:

sed -i 's/\r//' maintain.sh

答案 1 :(得分:0)

将此添加到脚本的开头? #!/bin/bash

这就是ubuntu不确定raspbian

的方法