netfishers-onl / Netshot

Network Configuration and Compliance Management
http://www.netfishers.onl/netshot
240 stars 57 forks source link

Need help for script #285

Closed TLigniere closed 7 months ago

TLigniere commented 8 months ago

Hello, So I'm trying to create scripts for my cisco devices but i find myself being stuck for the upgrade of the firmware with tftp. When launching my script, i end up with the following error since I can't confirm the files and address of the : "Error while waiting for a response from the device after command"

Here's my script : const Input = { TFTPAddress: { label: "TFTP Adress", description: "E.g. 10.0.0.1", }, NewFirmware: { label: "Firmware File name", description: "The name of the firmware that will be installed", }, };

function run(cli, device) { // Apply commands to upgrade const { TFTPAddress, NewFirmware } = cli.userInputs; cli.macro("enable"); cli.command(copy tftp://${TFTPAddress}/${NewFirmware} flash);

cli.macro("save");

}

Regards,

SCadilhac commented 7 months ago

Does this help? https://github.com/netfishers-onl/Netshot/issues/265#issuecomment-1646782899

TLigniere commented 7 months ago

I'll try and give you a return

TLigniere commented 7 months ago

Doesn't seem to work, i'll keep trying and keep you updated. Also I noticed a bug when trying to save a script, you need to delete the previous instance to save it otherwise it consider it cannot be added to the database.

TLigniere commented 7 months ago

For the record my script was this, this time; excuse me if i did mistakes but i'm still not accustomed to JS:

const Input = { TFTPAddress: { label: "TFTP Adress", description: "E.g. 10.0.0.1", }, NewFirmware: { label: "Firmware File name", description: "The name of the firmware that will be installed", }, };

function run(cli, device) { // Apply commands to upgrade and wait for const { TFTPAddress, NewFirmware } = cli.userInputs; cli.macro("enable"); cli.command(copy tftp://${TFTPAddress}/${NewFirmware} flash, { mode: { prompt: /Address or name of remote host [.]/, }, timeout:300000 }); cli.command(${TFTPAddress}, { mode: { prompt: /Source filename [.]/, }, timeout:300000 }); cli.command(${NewFirmware}, { mode: { prompt: /Destination Filename [.*]/, }, timeout:300000 }); cli.command(flash);

cli.macro("save");

}

TLigniere commented 7 months ago

So i found a workaround in Cisco IOS to avoid this issue, you can use the "file prompt quiet" so that the switch will not ask about the values, it will execute the command directly, In the end, with a few improvements, my script is the following :

const Input = { TFTPAddress: { label: "TFTP Adress", description: "E.g. 10.0.0.1", }, NewFirmware: { label: "Firmware File name", description: "The name of the firmware that will be installed", }, MD5Checksum: { label: "MD5 Checksum", description: "The original MD5 Checksum should be available on the cisco website when downloading a package" } };

function run(cli, device) { // Apply commands to upgrade and wait for const { TFTPAddress, NewFirmware, MD5Checksum } = cli.userInputs; let Verification = "" cli.macro("configure") cli.command('file prompt quiet') cli.command(do copy tftp://${TFTPAddress}/${NewFirmware} flash), Verification = (cli.command(do verify /md5 flash:${NewFirmware})) if (Verification.includes(${MD5Checksum})){ cli.command(boot system flash:/${NewFirmware}); cli.command("file prompt noisy"); cli.command("do reload"); } else { cli.command(do delete ${NewFirmware}) }
cli.command("do wr"); }