R
R
rdntw2013-06-10 22:19:45
Perl
rdntw, 2013-06-10 22:19:45

Write a simple script?

Good afternoon!
before with scripts in general did not deal.
you need to create the following in a text doc.
for example:
create vlan vlan2
configure vlan vlan2 tag 2
configure vlan vlan2 add ports all
...
create vlan vlan4093
configure vlan vlan4093 tag 4093
configure vlan vlan4093 add ports all
I would like to get a text file as output ...
what methods are there? would like to describe it in more detail...

Answer the question

In order to leave comments, you need to log in

5 answer(s)
N
nochkin, 2013-06-11
@rdntw

If there is no perl on Windows, then it's easier to make .bat. Something like:

@echo off
set /a "x = 2"
:while1
    if %x% leq 4093 (
        echo create vlan vlan%x%
        echo configure vlan vlan%x% tag %x%
        echo configure vlan vlan%x% add ports all
        set /a "x = x + 1"
        goto :while1
    )

Save this in create.bat and run:
create.bat > commands.txt Commands.txt
will appear with the result.

W
wlan, 2013-06-10
@wlan

#!/bin/bash

for x in $(seq 2 4093)
do
    echo "create vlan vlan${x}" >> /tmp/config.txt
    echo "configure vlan vlan${x} tag ${x}" >> /tmp/config.txt
    echo "configure vlan vlan${x} add ports all" >> /tmp/config.txt
done



One cycle, what for here a pearl I do not see sense. If the pearl is necessary, I can give later.
PS On the pearl will be the same practically. Only add open to open the file.

A
avalak, 2013-06-10
@avalak

Here is a simple script

#!/usr/bin/env bash
# ./scriptname.sh [filename]
# filename не обязательный параметр

# если аргумент был используем его, если нет значение по умолчанию
file=${1:-data.txt}
# если файл есть удаляем
[ -f "$file" ] && rm "$file"
# простой цикл от 2 до 4093 с шагом 1
for i in $(seq 2 4093); do 
  # дописываем в файл шаблон с переменной
  echo "create vlan vlan$i
configure vlan vlan$i tag $i
configure vlan vlan$i add ports all
" >> "$file"
done

R
raskumandrin, 2013-06-10
@raskumandrin

#!/urs/bin/perl
# ./script.pl > file.txt

print <<"EOF";
create vlan vlan$1
configure vlan vlan$1 tag $1
configure vlan vlan$1 add ports all
EOF
foreach (2..4093);

R
rdntw, 2013-06-11
@rdntw

Guys, thank you all very much... but how to use this on Windows? dopprog to put it seems?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question