Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Open Rednet
- rednet.open("top") -- Adjust the side according to your setup
- -- Function to remotely execute a command on a specific computer
- local function remoteExecuteCommand(computerID, command)
- -- Send a Rednet message to the target computer containing the command
- local success = rednet.send(computerID, command)
- -- Check if the command was sent successfully
- if success then
- print("Command sent to Computer ID:", computerID)
- else
- print("Failed to send command to Computer ID:", computerID)
- end
- end
- -- Function to remotely execute a command on all computers with a receiver
- local function remoteExecuteCommandOnAll(command)
- local successCount = 0
- local failureCount = 0
- -- Broadcast the command to all connected computers
- local computerIDs = rednet.broadcast(command)
- -- Check if any computers received the command
- if computerIDs then
- for _, computerID in ipairs(computerIDs) do
- successCount = successCount + 1
- print("Send program to computers")
- end
- else
- return
- end
- print("Command sent to", successCount, "computers.")
- end
- -- Prompt the user to enter the command
- print("Enter the command to run or 'all' to execute on all computers:")
- local command = read()
- -- Check if the user wants to run the command on all computers
- if command == "all" then
- -- Prompt the user to enter the command to run on all computers
- print("Enter the command to run on all computers:")
- local commandToRunOnAll = read()
- remoteExecuteCommandOnAll(commandToRunOnAll)
- else
- -- Prompt the user to enter the target computer ID
- print("Enter the target computer ID:")
- local targetComputerID = tonumber(read()) -- Convert input to number
- -- Remotely execute the command on the target computer
- remoteExecuteCommand(targetComputerID, command)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement