I have been trying to create a looping script which increments a number by 1 with each loop.
These are the commands:
Store | 1 | i |
Times | 5 |
Execute Script | return ${i} + 1; | i |
Echo | ${i} |
End
When the script loops, it outputs the following in the log:
echo: 1
echo: 11
echo: 111
echo: 1111
echo: 11111
I have tried this instead:
Execute Script | return ${i} ++; |
But this outputs:
echo: 1
echo: 1
echo: 1
echo: 1
echo: 1
I use this command to increment iterator i
Execute Script|return Math.floor(${i})+1|i
its abit of a long way round, but i've found that this process works:
storeEval ¦ 0 ¦ loop
echoandwait
while ¦ ${loop}<50
execute script
storeEval ¦ ${loop}+1 ¦ loop
endwhile
Related
I have a shell script that uses output from a sql query and based on the value of one column sends out an alert. However i don't think it's capturing the value. although the value is not greater than 0 yet it still sends out an email.
Any idea where i am going wrong? Thanks.
............................................................................
#!/bin/sh
psql -d postgres -U postgres -c "select pid,application_name,pg_wal_lsn_diff(pg_current_wal_lsn(), sent_lsn) sending_lag,pg_wal_lsn_diff(sent_lsn,flush_lsn) receiving_lag,pg_wal_lsn_diff(flush_lsn, replay_lsn) replaying_lag,pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn) total_lag from pg_stat_replication;"| while read total_lag;
do
echo $total_lag
lag1=$(echo $total_lag)
done
if [[ $lag1 -ge 0 ]]
then echo "Current replication lag is $lag1" |mail -s "WARNING!" abcd#mail.com
else
echo "No issue"
fi
............................................................................
this is the output of above query
pid | application_name | sending_lag | receiving_lag | replaying_lag | total_lag
-------+------------------+-------------+---------------+---------------+-----------
27823 | db123 | 0 | 0 | 0 | 0
27824 | db023 | 0 | 0 | 0 | 0
I'm trying to populate an array automatically.
These stepes just returns an array containing "foo". The "bar"-string I'm trying to push into it doesnt seem to be included.
execute script | return ["foo"] | testVar
execute script | ${testVar}.push("bar") |
echo | ${testVar}
What am I doing wrong?
I use this approach to update an array in Selenium IDE
execute script | return ['foo'] | testVar
execute script | return [${testVar}, 'bar'] | testVar
echo | ${testVar}
UPDATE
Previous solution is not correct because of wrong value will be stored in the variable testVar. It will be array of array of arrays. So here is the correct one:
execute script | return ['foo'] | testVar
execute script | tmp = ${testVar}; tmp.push('bar'); return tmp; | testVar
echo | ${testVar}
Let's say I have two String variables: var1 and var2.
Is there any command on Selenium IDE (maybe storeEval with some javascript code), with which I can create an array and add the 2 variable values to it? Example:
var1 = "abc"
var2 = "def"
array = ("abc","def")
P.S: the array cannot have a fixed length. In this case I have just 2 variables, but in other scenarios I may have more than 10 variables, so I would need to create a loop and add all 10 variable values to the array.
Thanks!
It's pretty simple but isn't obvious
storeEval | ['one','two'] | array
storeEval | storedVars['array'][1] | second
echo | ${second}
Or simpler but with much less safety
storeEval | ['one','two'] | array
echo | javascript{storedVars['array'][1]}
Adding new item dynamically
getEval | storedVars['array'].push('three')
You can make loop using selenium IDE flow control for example. Like:
storeEval | 0 | i
while | storedVars['i']<storedVars['array'].length
echo | javascript{storedVars['array'][storedVars['i']]}
storeEval | ${i}+1 | i
endWhile
I hope it will help
I'm writing a perl script which needs to parse a file (or more specifically, a known sub in the file) find a specific function call, and retrieve all the arguments for that call. For example:
sub MySub {
# some code here...
# ...
MyFunction ([q{I}, q{want}], [qw(to get)],
["these", "arguments"]);
# ...
# more code...
}
I've been able to parse through the file grab the appropriate line/lines for the function call, and then I wrote my own local "MyFunction" which can grab the args. Then I use a stringy eval to call that function and get the arguments. Example:
sub MyFunction {
return #_;
}
# Not actually doing this, but this is what I might get from parsing:
my $lines = 'MyFunction ({arg1 => "hashref"}, ["arg2", "arrayref"], "etc...");';
my #arguments = eval $lines;
This works great, except for the fact that I'm using a stringy eval. The problem with parsing the argument directly out of the string is there are many different formats (including multiple lines) that are possible. So I guess is there an easy way to parse the arguments directly out of the string, or to call the function without a stringy eval?
Thanks a lot for any help!
You don't have to eval if you don't want to. You can use the name to get the symbol and then use that to get the code ref.
my $func = do {
no strict 'refs';
*{'main::MyFunction'}{CODE};
};
my #arguments = $func->( {arg1 => "hashref"}, ["arg2", "arrayref"], "etc..." );
Parsing Perl is hard (and there's a folk theorem that only Perl can parse Perl). Parsing perl with your own hand-rolled string hack is likely to end in disaster in all but the simplest cases. What you really want is a tool that can parse Perl and give you the arguments.
Our DMS Software Reegineering Toolkit can do this. See parse tree below,
obtained from a file that contains exactly OP's MySub example text:
C:\DMS\Domains\Perl\Tools\Parser>run ..\domainparser ++AST C:\temp\test.pl
Perl~Perl5 Domain Parser Version 2.6.15 DEBUG BUILD
Copyright (C) 1996-2015 Semantic Designs, Inc; All Rights Reserved; SD Confidential
Powered by DMS (R) Software Reengineering Toolkit
Using encoding Unicode-UTF-8?ANSI +CRLF +1 /^I
432 tree nodes in tree.
(Perl#Perl~Perl5=1#5c21d20^0 Line 1 Column 1 File C:/temp/test.pl
(statements#Perl~Perl5=10#5c21c80^1#5c21d20:1 Line 1 Column 1 File C:/temp/test.pl
(subroutine_head#Perl~Perl5=551#5c73680^1#5c21c80:1 Line 1 Column 1 File C:/temp/test.pl
(IDENTIFIER#Perl~Perl5=573#5c735e0^1#5c73680:1[`MySub'] Line 1 Column 5 File C:/temp/test.pl)IDENTIFIER
(prototype#Perl~Perl5=552#5c73640^1#5c73680:2 Line 1 Column 11 File C:/temp/test.pl)prototype
(attributes#Perl~Perl5=554#5c73660^1#5c73680:3 Line 1 Column 11 File C:/temp/test.pl)attributes
)subroutine_head#5c73680
(block#Perl~Perl5=4#5c21640^1#5c21c80:2 Line 1 Column 11 File C:/temp/test.pl
precomment 3:1 `# ...'
precomment 3:2 `# more code...'
(statement#Perl~Perl5=21#5c7cf40^1#5c21640:1 Line 5 Column 5 File C:/temp/test.pl
|(call_statement#Perl~Perl5=561#5c209a0^1#5c7cf40:1 Line 5 Column 5 File C:/temp/test.pl
| (IDENTIFIER#Perl~Perl5=573#5c73920^13#5c210a0:1#5c73ec0:1#5c778c0:1#5c21080:1#5c73e00:1#5c77860:1#5c209a0:1#5c7f860:1#5c73d60:1#5c77840:1#5c7f840:1#5c73560:1#5c777e0:1[`MyFunction'] Line 5 Column 5 File C:/temp/test.pl
| precomment 0:1 `# some code here...'
| precomment 0:2 `# ...')IDENTIFIER
| (L20#Perl~Perl5=514#5c7f240^3#5c206c0:2#5c209a0:2#5c21020:1 Line 5 Column 17 File C:/temp/test.pl
| (L20#Perl~Perl5=514#5c7b540^3#5c7f240:1#5c7c640:1#5c738e0:1 Line 5 Column 17 File C:/temp/test.pl
| (L1_term#Perl~Perl5=187#5c7a700^11#5c7abc0:1#5c7b540:1#5c7c860:1#5c7d280:1#5c7b620:1#5c7ad60:1#5c7a9a0:1#5c20840:1#5c7c1c0:1#5c7b8a0:1#5c7aaa0:1 Line 5 Column 17 File C:/temp/test.pl
| |(L20#Perl~Perl5=514#5c77da0^2#5c7a700:1#5c7a380:2 Line 5 Column 18 File C:/temp/test.pl
| | (constant#Perl~Perl5=101#5c73180^6#5c77bc0:1#5c77da0:1#5c77d60:1#5c77a00:1#5c7a420:1#5c77ae0:1 Line 5 Column 18 File C:/temp/test.pl
| | (string_prefix#Perl~Perl5=120#5c731a0^1#5c73180:1 Line 5 Column 18 File C:/temp/test.pl)string_prefix
| | (ORDINARY_STRING#Perl~Perl5=604#5c77400^1#5c73180:2[`I'] Line 5 Column 19 File C:/temp/test.pl)ORDINARY_STRING
| | )constant#5c73180
| | (constant#Perl~Perl5=101#5c77e00^6#5c7a6a0:2#5c7a740:2#5c7a2a0:2#5c7a160:2#5c77da0:2#5c7a140:2 Line 5 Column 24 File C:/temp/test.pl
| | (string_prefix#Perl~Perl5=120#5c7a020^1#5c77e00:1 Line 5 Column 24 File C:/temp/test.pl)string_prefix
| | (ORDINARY_STRING#Perl~Perl5=604#5c7a000^1#5c77e00:2[`want'] Line 5 Column 25 File C:/temp/test.pl)ORDINARY_STRING
| | )constant#5c77e00
| |)L20#5c77da0
| )L1_term#5c7a700
| (L1_term#Perl~Perl5=187#5c7b420^14#5c7b600:2#5c7b780:2#5c7b620:2#5c7c7c0:1#5c7e880:1#5c20600:1#5c7d160:1#5c7c0c0:1#5c7bf00:2#5c7bf80:2#5c20c20:1#5c7c360:1#5c7b540:2#5c7b560:2 Line 5 Column 34 File C:/temp/test.pl
| |(qw_constant#Perl~Perl5=113#5c7b260^1#5c7b420:1 Line 5 Column 35 File C:/temp/test.pl
| | (WORD_LIST_STRING_START#Perl~Perl5=630#5c7b180^1#5c7b260:1["("] Line 5 Column 37 File C:/temp/test.pl)WORD_LIST_STRING_START
| | (word_list#Perl~Perl5=117#5c7b240^1#5c7b260:2 Line 5 Column 38 File C:/temp/test.pl
| | (word_list#Perl~Perl5=117#5c7b200^1#5c7b240:1 Line 5 Column 38 File C:/temp/test.pl
| | (word_list#Perl~Perl5=116#5c7b1c0^1#5c7b200:1 Line 5 Column 38 File C:/temp/test.pl)word_list
| | (WORD#Perl~Perl5=633#5c7b1a0^1#5c7b200:2[`to'] Line 5 Column 38 File C:/temp/test.pl)WORD
| | )word_list#5c7b200
| | (WORD#Perl~Perl5=633#5c7b1e0^1#5c7b240:2[`get'] Line 5 Column 41 File C:/temp/test.pl)WORD
| | )word_list#5c7b240
| | (STRING_END#Perl~Perl5=620#5c7b220^1#5c7b260:3[")"] Line 5 Column 44 File C:/temp/test.pl)STRING_END
| |)qw_constant#5c7b260
| )L1_term#5c7b420
| )L20#5c7b540
| (L1_term#Perl~Perl5=187#5c20260^12#5c20e80:2#5c20ea0:2#5c20f20:2#5c20f60:2#5c205c0:2#5c20600:2#5c20620:2#5c20380:2#5c7f240:2#5c7f260:2#5c7e880:2#5c7e8a0:2 Line 6 Column 9 File C:/temp/test.pl
| (L20#Perl~Perl5=514#5c7e7e0^1#5c20260:1 Line 6 Column 10 File C:/temp/test.pl
| |(constant#Perl~Perl5=103#5c7d820^5#5c7de60:1#5c7e7e0:1#5c7e140:1#5c7f940:1#5c7dd60:1 Line 6 Column 10 File C:/temp/test.pl
| | (INTERPOLATED_STRING_START#Perl~Perl5=621#5c7d5e0^2#5c7d840:1#5c7d820:1["""] Line 6 Column 10 File C:/temp/test.pl)INTERPOLATED_STRING_START
| | (interpolated_string_content#Perl~Perl5=130#5c7d800^2#5c7d840:2#5c7d820:2 Line 6 Column 11 File C:/temp/test.pl
| | (interpolated_string_content#Perl~Perl5=129#5c7d7c0^1#5c7d800:1 Line 6 Column 11 File C:/temp/test.pl)interpolated_string_content
| | (ORDINARY_INTERPOLATED_STRING_CONTENT#Perl~Perl5=642#5c7c6e0^1#5c7d800:2[`these'] Line 6 Column 11 File C:/temp/test.pl)ORDINARY_INTERPOLATED_STRING_CONTENT
| | )interpolated_string_content#5c7d800
| | (STRING_END#Perl~Perl5=620#5c7d7e0^2#5c7d840:3#5c7d820:3["""] Line 6 Column 16 File C:/temp/test.pl)STRING_END
| |)constant#5c7d820
| |(constant#Perl~Perl5=103#5c7dc40^3#5c7e7e0:2#5c7e840:2#5c7e8e0:2 Line 6 Column 19 File C:/temp/test.pl
| | (INTERPOLATED_STRING_START#Perl~Perl5=621#5c76320^4#5c7dec0:1#5c7e420:1#5c7e400:1#5c7dc40:1["""] Line 6 Column 19 File C:/temp/test.pl)INTERPOLATED_STRING_START
| | (interpolated_string_content#Perl~Perl5=130#5c76800^4#5c7dec0:2#5c7e420:2#5c7e400:2#5c7dc40:2 Line 6 Column 20 File C:/temp/test.pl
| | (interpolated_string_content#Perl~Perl5=129#5c76140^1#5c76800:1 Line 6 Column 20 File C:/temp/test.pl)interpolated_string_content
| | (ORDINARY_INTERPOLATED_STRING_CONTENT#Perl~Perl5=642#5c76120^1#5c76800:2[`arguments'] Line 6 Column 20 File C:/temp/test.pl)ORDINARY_INTERPOLATED_STRING_CONTENT
| | )interpolated_string_content#5c76800
| | (STRING_END#Perl~Perl5=620#5c76180^4#5c7dec0:3#5c7e420:3#5c7e400:3#5c7dc40:3["""] Line 6 Column 29 File C:/temp/test.pl)STRING_END
| |)constant#5c7dc40
| )L20#5c7e7e0
| )L1_term#5c20260
| )L20#5c7f240
|)call_statement#5c209a0
)statement#5c7cf40
)block#5c21640
)statements#5c21c80
)Perl#5c21d20
You still have to walk over the parse tree and pick out the arguments. If you do pick up subtrees, they can be prettyprinted to generate the surface syntax string.
I have the following powershell script to count lines per file in a given directory:
dir -Include *.csv -Recurse | foreach{get-content $_ | measure-object -line}
This is giving me the following output:
Lines Words Characters Property
----- ----- ---------- --------
27
90
11
95
449
...
The counts-per-file is fine (I don't require words, characters, or property), but I don't know what filename the count is for.
The ideal output would be something like:
Filename Lines
-------- -----
Filename1.txt 27
Filename1.txt 90
Filename1.txt 11
Filename1.txt 95
Filename1.txt 449
...
How do I add the filename to the output?
try this:
dir -Include *.csv -Recurse |
% { $_ | select name, #{n="lines";e={
get-content $_ |
measure-object -line |
select -expa lines }
}
} | ft -AutoSize
I can offer another solution :
Get-ChildItem $testPath | % {
$_ | Select-Object -Property 'Name', #{
label = 'Lines'; expression = {
($_ | Get-Content).Length
}
}
}
I operate on the. TXT file, the return value is like this ↓
Name Lines
---- ----
1.txt 1
2.txt 2
3.txt 3
4.txt 4
5.txt 5
6.txt 6
7.txt 7
8.txt 8
9.txt 9
The reason why I want to sort like this is that I am rewriting a UNIX shell command (from The Pragmatic Programmer: Your Journey to Mastery on page 145).
The purpose of this command is to find out the five files with the largest number of lines.
At present, my progress is the above content,i'm close to success.
However, this command is far more complicated than the UNIX shell command!
I believe there should be a simpler way, I'm trying to find it.
find . -type f | xargs wc -l | sort -n | tail -5
I have used the following script that gives me lines in files of all sub directories in folder c:\temp\A. The output is in lines1.txt file. I have applied a filer to choose only file types of ".TXT".
Get-ChildItem c:\temp\A -recurse | where {$_.extension -eq ".txt"} | % {
$_ | Select-Object -Property 'Name', #{
label = 'Lines'; expression = {
($_ | Get-Content).Length
}
}
} | out-file C:\temp\lines1.txt