reason it has printed only unique data and that's what this particular command hyphen d does okay um then what does we have which we use hyphen i we already used okay i'm just trying to recollect if i use any other option with this hyphen s we use but that is not much important we use option hyphen d okay we have one more option called as hyphen d option okay what this option does is we can just again it displays only the record which are duplicated okay can you see here when i used option unique hyphen d it is giving me record one and record two only right so that's how we can use the various options again there are many options to this particular command but these are the repetitively used in our day-to-day task that's what i wanted to explain to to get more details you can refer the manual by using command man space unique you'll get the complete manual with all the options which which can be used along with this unique command but i i just explained this four to five options which we use day-to-day basis like option i to ignore case sensitivity options c to c the count option u to get the unique data hyphen d to get the duplicated data okay so that's what i wanted to talk about this unique command in units which is basically one of the filter command okay and you know you can use this any filter command basically in piping okay so you can basically coordinate two commands to get the data and just for example let us say if i want to use something like this cat so if i use cat data this will basically display the data on my console okay so if i want to let us say display the data and then i want to find out the unique data then i can use cat data let me use pipe unique okay can you see you can use unique command this way as well like i'm giving the file name to cat command so that cat command will read the data and the data which is read by cat command is given to unique command which will process by unique command then okay so that's what about unique command in unix or linux in fact thank you hello welcome back welcome to the course of unix for tester in this video i'm going to talk about how you can compare two files using command biwf diff command okay so in my last video i have shown you how we can use cmp command for comparison and which was basically doing byte by byte comparison okay now in this case if i use diff command the comparison will happen line by line if i was using diff command it was showing me the open the difference was found in line 1 and byte 16th okay but in diff command the comparison will happen line by line and which is something which i find most useful as a testing point of okay so let's see how it works okay so uh okay let me show you the syntax basically let me okay so the syntax is something like diff which is my command itself and then i have some options which i can specify okay again there are a huge number of options for this particular command which i'm not going to talk about all but just couple of options which we use more frequently and which we need basically okay those options i'm going to talk here and then followed by my file one and file two okay so this is the syntax which is very simple okay so let's see how diff works okay so let me use diff command now diff now my file one is new data in which i have some data and again the it's same copy with some minor changes and new data one okay i'll hit enter and you should see something like this okay now uh there are few things you should notice over here okay so give me a second so what you see over here is you see some some words like one c one and you see some less than symbol you see some greater than symbol you see something 18c 18 something like that okay so what are these things okay so what this basically diff command tells you the diff command tells you that what and all changes are required into the first file so that it will look exactly as same as your second file i have two files file new data and new data one so what this particular command will tell you what and all changes you need in new data which is my file one so that it will look exactly as same as uh my second file which is new data one and basically the comparison happens line by line okay so unlike its fellow member like we have different commands for comparison like cmp as i said earlier and we have one more called as form c o m m it tells uh basically they tells us uh bite by bite comparison but in this case we see the comparison line by line okay so it basically tells us which line uh in one file have to be changed to make the two files identical okay so what these things are now one c one less than symbol greater than symbol so uh basically this diff command give you the output and it uses some special symbols and instruction to uh give you the output okay so uh there are the two things the very very first one is the special symbols which are a c and d so as the name suggests it is a for add c for change and d for delete a for add c for change and d for delete okay now what it tells i'll tell you okay and we have two more things like we have one less than symbol which refers first file okay and we have some greater than symbol which second file okay now something should be clear to you okay now what the first uh this one c one tells me okay so this one c one tells me that okay this one is file one okay and this one is sorry this one is line one from file one and c is nothing but change and this one is again line one from file two okay so what this basically is telling me you need a change in line one of file one and line two of file two okay and where that's where that change is you can see the very first is less than symbol that is uh this particular line is from my first file okay so though you can see the file the following r and in r i have r in upper case in first file and in second file i have it in lower case that's the only change what i have in this particular uh line okay so because of which i can see this particular difference okay so i hope you're clear now this one refers line one from file one c means you need particular change in line one of file one so that it will look exactly same as line one from file two and this one refers to line one from file two less than symbol refers first file this is required this is line from my first file and this is the greater than symbol as refers line one from my second file okay on the similar line you see something next to that you see something seven c seven uh this means there is a difference ends line number seven of file one and in order to make uh the lines equal you need to do the change in line number seven c means change okay so you need to do the change okay so you can see the different difference lines like less than symbol means first file so the first file has something like optical description and the second file means greater than symbol has something like eggs description so you need to have change over here okay and again similar line i have something in line number 18 you where again you need change now why i see only ccc that is for change over here because i what i did it i simply went to the file i made a copy and i did some changes in that but if you have something extra into the file then you something like addition or something like deletion over there right but in my case since i have only changed it i'm not saying those things okay but maybe you can give a try by adding some content or deleting some content from another file uh you should get that okay so that's basically this is basically where uh very useful comparison for me if i want to compare two files okay and now let us take an example i want to ignore uh the case sensitivity if you see the first difference it is because of case sensitivity i have upper case r and i have lower case r and unix is quite case sensitive okay let us say i want to ignore case sensitivity okay so what i can do is i can use option hyphen i again which is option hyphen i is the common for most of the commands which is for to make case insensitive okay so i can use something like diff option hyphen i okay and followed by my file one new data and another file new data one okay now if you see when i didn't use option hyphen i i saw three differences the very first one was because of this r okay upper case and lower case but when i use option hyphen i i don't see the very first difference which was because of uh case sensitivity i just see other two differences okay so this hyphen i is to skip uh is to make your comparison case insensitive okay and we have another option which we use uh mostly which is to uh ignore uh white spaces okay if you have some white spaces in your file at the end of the file or something like that and if you want to ignore them you can use one of the option called as hyphen b in my file since i do not have it i cannot show and demo it to you but this will be used when you have some white spaces before or after your file and if you want to ignore them from comparison you can use this option basically hyphen so this is about how we can compare the file by using dip command okay and there are many number of commands which you can find in the manual okay so if i see man space dip that is i can get the dip manual and you can say you can find it has a huge number of commands okay so you can as per your requirement you can go here and you can try but the if i just want to compare the two files the two come the two options are useful to me which are my option hyphen i to ignore case sensitivity because i can see all the differences like this okay and what else okay there is one more option give me a second let me check there is one more option like hyphen why i guess let me check if it is di wf and if i use option as hyphen y and new data new data and new data one okay uh okay so this file i will not be able to see it correctly but i'll just tell you what this particular command does this particular command does the comparison column by column so it will put the file one in column one and file two in column two and it will show you the comparison results okay so you two files are like here you won't be able to see that much clearly because the files are big one but you can see something like some pipe symbol over here that means there is a difference over here and you can see the difference is in between r this the following r i have uppercase r over here and then i have this lowercase r over here in my second file this is the one okay again i see second pipe over here that means there is a difference over here you can see the first file has octal second file has hex okay and the third pipe is over here that means some differences over here that is in my first file i have z9 and in my second file i have a9 right so if you want to have column by column comparison if you want to put both files into two columns then you can use this option y uh hyphen y option as one of the option basically okay so this is how you can do line by line comparison using diff command which i personally feel more useful to me when i want to compare two files in unix okay as compared to byte by byte comparisons rather okay so that's it thank you hello welcome back welcome to unix for tester course this is a quick video in which i'm going to talk about how we can compare two files using cmp command okay so comparing file must be a repetitive task what we do most of the day when we deal with unix systems especially as a part of testing activities so for for doing file comparisons could be any any type of file so for doing file comparison there are three to four different commands out of that i'm going to talk about cmp command in this video okay so the cmp command is basically um as i said used to compare two files but the comparison happened byte by byte okay so if i go to my unix terminal and if i check the help document for cmp by using man cmp i should get some description like it is used to compare the two files byte by byte okay and the syntax for this particular compare command is like this cmp which is for compare followed by some options okay what and all options we have that i'm going to talk okay and followed by your file one and file two and if you want to skip any records then we can specify with options okay so uh we have some options like uh hyphen b hyphen i then we have hyphen uh l hyphen uh s to suppress the output we have four to five options okay so let's go to that quickly let me quit this okay now i have two files basically okay i have two files my first file is new data okay and in this file i have some data okay so in this file i have some data and i have made some changes into this file like i changed this lowercase r to uppercase r in this file and i changed a couple of things here and there okay uh so this is the my first change what i have in my file uh in one file i have small case r and in in one file i have uppercase r okay now let us see how this compare command work in this case okay so uh uh the syntax is basically cmp okay then option which are optional basically which i'm going to show you in some more time and followed by my file one name my file one is new data and my next file is new data one where i have made changes okay new data one these are the two to compare new data and new data one and i'll hit enter and you can see new data and new data one differs at byte 16 of line one so the comparison is happening basically byte by byte okay and wherever this particular uh program finds the uh difference it is going to terminate the program and giving me the output where is where my first mismatch found right so the first mismatch was on line one at byte 16 okay so this might not be that much useful in this way okay but uh uh if you want to use it in shell script then this particular utility could be useful i'll tell you how okay now let us see a few options what we have so we have uh option hyphen b okay so if i use cmp hyphen b okay uh it is basically used to print uh differing byte okay the the bytes which are differing it is used to print that so i'll use cmp hyphen b i can give file one as new data and file two as new data one and you can see there is something like new data and new data one differ byte 16 line one is 12 some control j and 160 r okay so there is some configuration issue with my unique system so that's the reason i'm getting this but in actual you should get like uh in this case you will get like upper case r and lower case r that's what the difference in between two bytes okay so this hyphen b option is used to print the bytes which are different okay so we have one option called as hyphen b for that now we have another option called as hyphen i okay uh if you skip uh some bytes from comparison let us say what i want to do is i want to skip uh let us say first uh since the mismatch is on 16 byte let me say i'm going to skip my first 20 bytes so for that i'm going to use option hyphen i followed by how many bytes i want to skip from both the files so let us say i want to skip 20 bytes uh from both the files the first 20 bytes should not be compared and comparisons should start from 21st byte okay what are my files my file is new data and new data one okay and now can you see the file is having another difference and it is on line 7 byte 267 that is the second change i made but now can you see clearly that it has skipped this particular comparison where i had the difference on line uh 1 on byte 16 so this particular comparison has been skipped and now there is a difference in line 7 byte number 267 okay so at work now uh you might have situation where uh you uh let me say again you might need to skip let us say first 10 byte from file one and 12 byte from file two might be you might have some few few junk special type of characters or few differences in the initial wording so if you want to skip let us say first 10 bytes from file one and 12 bytes from file then you can use syntax something like this okay so since i do not have that kind of file i'm not going to show you that but you can specify sorry there should be hyphen i as well here let me say again so it should be like hyphen i then byte to be skipped from first file let us i want to skip 10 byte from the first file colon byte to be skipped from second file let us i want to skip 12 byte from the second file and my both file file 1 and file 2 right so it will work in that way so yeah so again we can use hyphen i option for that okay let us take another example where you want to uh compare only first 10 byte okay so by using hyphen i option we skipped first 10 byte or first 12 byte whatever right but now if in case if you just want to compare only few bytes from some file then you can use hyphen n as one of the option and let us say you want to compare first 15 byte of both file and my both file are new data and new data one now in this case since my file had a difference on byte 16 of line one and i just said just compare first 15 byte so that's the reason i'm not getting any error message over here so if i'm not getting any uh message warning or anything that means the file comparison is successful so what we compared we just compared first 15 bytes using option hyphen n and okay and one last option i want to show you is hyphen s option okay so this hyphen s option is basically used to suppress the output okay so whatever output you see the comparison output in this case the output is something like this new data new data file differ add by 16 line one whatever this is okay so if you don't want to see this output you want to suppress it then you can use the option called as hyphen yes okay and you can give your file name new data and new data one so see i have the differences but the output is getting suppressed okay but in this case it will return some uh exit status so it will return exit status one and two one if it is success and two is there is some message something like that so now where it should be where it can be used it can be used uh in your uh shell script wherever you want to write a script and in that in particular script if you have some functionality where you want to compare the file and if you just want to check if both files are equal or not then you can use this uh hyphen s option from where you will get the exit status okay anyway we don't want it to use for our file comparison so uh as a tester i will not basically use this cmp option because it is not much useful to me um but this is one of the utility program what unix has provided okay so in next video i'm going to show you we have another two options to compare the files uh diff and one more we have so that is what i'm going to explain in next video okay so stay tuned thank you hello welcome back welcome to the course of unix for tester uh this would be a very short video where i'll talk about variables in unix or linux so though as a software tester it is not necessary for us to understand uh variables in detail i'm just going to show you uh at least how we can get the values for system variables okay so uh let us try and understand what is variable first okay so in any programming languages when we work with okay we assign some value to the variable in order to make it dynamic okay like i define some variable as name is equal to something like i define some variable and i assign some value to it right so that is what my variable is that is something used to store some value um which basically refers some memory location okay and in unix there are two kinds of variables first one is system defined variable and second one is user defined variable okay so system depends variables are something which are created and maintained by unix or linux itself okay so this type of variables are defined in capital letters okay so let us take a very simple example uh if i go to my shell unix shell okay so in my last video i shown you something like if i do something like eco uh dollar and uh shell okay if i do something like that then i will get what uh shell i am going to use right so here this shell is nothing but my system defined variable it is defined and maintained by system itself i can just access it if i want i can set its value and just by overriding that is something which i can do in the path variable uh okay in this in some folder under path variable that is i can do but i'm not supposed to do until and unless i'm very much sure if i want to make those changes for specific requirement again let us take some example like if i want to get my uh home location like okay so what i can do is i can use something like eco dollar home so this home is again another system defined environment variable okay and another example i can show you like let me check if does this eco sorry oh yes like walk over here it works in linux i'm not sure if it works here yeah it works over here and it is linux you know which is uh the unix flavor basically okay and we we all know right we have some environment variable in uh windows operating system like if you if we install let us any tool then let us see if i install Java then i need to configure environment variable so that it refers to particular environment a particular version of Java right on the similar line there are environment variables okay and uh everything is maintained under this path right so you can go to this location and do some changes if you want to do uh i suggest a lot to do okay and okay so this is how again there are many uh variable system defined variable a few of them i have listed over here like we have bash bash version then home which i have shown then log name our logging in name then we'll style then we have path ps1 pwd which will use me the present working directly like to get your present working directly i can directly use pwd like this or i can even do something like eco dollar pwd like this okay so the thing to remember here is if you see anything in uppercase uh any variable in uppercase that is your system defined variable okay now the second second variable type is your user defined variable okay so though as a software tester we do not need it let me show you how quickly we can define it and uh retrieve the environment okay so defining the variable uh mostly we will be using this thing in uh shell scripting right and as a tester i'm not going to do any shell scripting if that is then i'm not a software tester right i'm not complete data still developer but let us see how we can do that okay so what you can do is you can simply type your command let us say i want to create variable of name uh var and i want to assign some value to it which is 99 okay for example okay i have set it that's it my variable has been set and now if i want to access that value how i can access it eco dollar var and it should print 99 so this is my uh user defined variable which we should write it in lowercase right if it is some different that is an uppercase user defined should be in lowercase right so this was a very short video about variable type though it is not in detail because as a software tester i'm not going to deal with uh variables and all of them but i just wanted to show you some uh variables and how we can access them basically okay so and that's it i have uh for this video thank you hello welcome back welcome to the course of the next four tester uh in this video i'm going to talk about shell script okay so i'm going to talk about how we can create a shell script how we can execute a shell script in fact i'll start with what is shell script form okay so uh first let us talk about what is shell script okay so if you are aware in windows we have something called as batch file okay and i have one simple example where i have created a batch file okay so if you want to execute any script from goss okay uh then we use this basically windows batch file okay with dot bat extension okay if i open and if i show you something like this this is my batch file okay and these are the uh three different commands which i'm going to execute from my batch file okay so uh like if i don't use this batch file then what i need to do is i need to execute my command one first then i need to execute my second command then i need to execute third command in the sequence one by one manually but instead of that what i did is i wrote all three commands one by one in a line and i saved that particular file with dot bat extension that is batch file and simply i can double click on that batch file or even i can call it from my uh command prompt and the all the commands from that particular part it executed okay on the similar line if i wanted to do some same thing for linux then there is something called a shell script okay so basically shell script is a text file that contain a sequence of command for a unix based operating system so let us say in unix i want to do some processes like first i want to navigate to some directory then i want to read text file from the directory i want to process text file then i want to save the process data into some other text file and blah blah blah we have many operations which which can be achieved with uh unix right so if i want to do all those operations one by one manually it is very much time consuming i need to write a command uh each time uh for each uh command which i want to execute basically one by one manually right that is pretty tedious task so a unix shell script is a text file that contains sequence of all these commands which you which you want to execute one by one okay uh it's called a script because it combines two words script in a single file that is a sequence of commands that would otherwise have to be presented to the system in the form of keyboard one at a time right and the shell is the operating system systems command interpreter right because see what kind of operating system i'm using i'm using uh unix operating system and its interpreter is shell okay i'm going to show you where the shell interpreter is so based on these two combination like since i have a shell interpreter and i am writing uh all my command into a file which the script so that is why it is basically called as a shell script okay uh now i'm going to let us uh i'm not basically going to create a shell script but i'm going to existing shell script which i have created okay so if i do ls over here uh if you see any file uh here which is ending with dot ssh extension is called as your shell script okay so this is my shell script which is script dot ssh okay so as i said in windows batch file we have uh like we will be writing a text file with dot bat extension but in case of unix it will be uh file ending with dot ssh extension that will be termed as your shell script okay now let us view the content of this shell script what this particular shell script contains okay so let me do vi script dot ssh and this is basically my shell script okay so uh the very first line you see something like hash then exclamation symbol and then you see some path like slash bin slash ssh okay first let us go and check what this particular path is okay let me go to slash bin and let me check what and all i have here i have many things let me check if i have sh anything called as sh uh yes i do have okay so let me do ls iPhone LDR okay and let us check uh what is this sh is okay let me set in i saw i said somewhere it is there uh yeah so it is okay and this sh is basically uh special kind of directory okay so let me check if i can view its content okay actually i it is basically a file but i cannot view its content right because it is a interpreter for me right so i cannot open the interpreter and i cannot view the content right so let me quit fine so this is the basically location where uh my interpreter is slash bin slash sh okay that's what i wanted to show you now let me go to my shell script let me go to my home directory okay now i have my shell script over here okay and let me open it again so the very first line as i said uh contains the interpreter right so this is the very important line which tells unix operating system that okay execute the below commands with the help of this particular interpreter okay so this is called a shebang okay this complete line is called a shebang okay so i this is my basically a shell script and in shell script you can find i have uh i have some commands which i am going to execute one after another okay so this eco is my first command which i'm going to execute then after that i'm going to execute another eco then i'm doing some while look over the line which i'm going to read the data from my input file and then again finally i'm going to do eco so i'm going to execute the commands one by one so uh in order to execute all cringe right because i don't want to execute one after another go go there and execute manually i don't want to do that so what i did is i just combined all of them into one file called a shell script okay so this what this shell script is basically doing it is reading the data from input file dot txt okay so we know that this less than symbol and greater than symbol are the ioridirectional operators basically we can call them so this less than symbol is used to read the data and this right greater than symbol basically used to write the data into uh file right so this double uh greater than symbol is basically used to append the data to the output file okay so this shell script is basically reading the data from my input file and simply writing the data to output file by writing over all the lines okay that's the pretty simple example what i have okay now let me come out of this and let me tell you now how we can execute this shell script okay so basically there are two ways how we can execute the shell script so the very first way is you can refer the current directory that is with the help of dot and then give the name of your shell script which is script dot message okay so if i hit enter you can see my shell script execution is completed because i can see some messages are printed and if i see some file would have been generated but that's when i know that file is generated okay but since i see this message that means my shell script execution is completed okay but whenever you create a shell script by default it does not have a permission to execute that particular shell script okay and how can you see the permissions if you do ls-ltr you will see go to your shell script that is script.sh and here you will see some permissions right so the very first 10 bytes you will see starting from second byte rwx which are the permissions for user then second rwx permission for user group third rwx permission for others right so this is something which i set by myself okay but if you are doing it first time then you will have something like i'm just changing the permission back to the normal level ch mode i'm setting it to 640 and script.sh okay so this is how basically whenever you will create this first time you will see something like this and let me check what and all permission it has now so script.sh you can see it has only read rate permission for user and at the fourth place you can see it has a hyphen that means it does not have the execute permission okay and if i try to execute the script without execute permission i should see the error message called as permission denied okay so in order to execute any shell script we need to do the permission so you need to do the permission whether you want to execute this shell script by your user name or maybe all other users from particular group or maybe anyone else can execute this particular shell script so you can do permission accordingly right so you can refer my one of the video where i talked about file permission okay i have talked about all these things like how we can change the file permission using ch mode command okay so for now i'm setting the permission 777 that means i'm i'm giving all the accesses to all all the like users user group and others right and my script is script.sh okay and if i try to execute the same shell script now script.sh now this time i should see my script got executed right so this is the one way how we can execute the shell script navigate to the directory where your shell script is and then use dot slash your script name okay another way to execute your shell script is again navigate where your shell script is currently i'm in the same directory where my shell script is and then use sh which is basically a command or you can say utility program which basically runs your shell script and then give the name of your shell script which is script.sh and if i hit enter i should see my script execution is completed right so these are the two way basically how we execute the shell script okay so that's what i wanted to show you in this video basically what is shell script how we can create a shell script and how to execute okay so see as a task engineer whenever we deal with any system with unix operations and all we are not going to create any shell script right because that's the job of data stage developers or unix developer whoever it is what my job is my job is to execute the shell script verify the output file if the output file is getting generated if the contents are correct and all those things right my job is to execute the shell script and verify the results not to write the shell script or what are the contents they are in the shell script but i should have a little bit idea okay shell script is like this it looks like this it works like this and other things right so that i can get even more interest and i can i may get few different things into my execution okay so that's what i wanted to talk in this video okay so thank you hello welcome back welcome to the course of unix protesters manually learn how we can automate the unix processes which can be used with any test automation framework so in this video i'm going to talk on how to automate the unix processes so what are the different unix processes we have like we might need to execute the shell script we may need to send the file we might need to check if my file is existing on server if i might need to delete the file is existing or create file or might be receiving file from my unix server to my local machine for further processing for further validation it could be anything like so we can automate all those unix processes so that i can accommodate them into my test automation framework okay so let us take an example i have some application where i input some data on my web application which let us say which you have automated with selenium okay and then you have a part of unix shell script execution let us say after though after that shell scripts get executed then only your something happens okay and then you need to verify that particular something part into your ui again or into your database or so somewhere okay so you have automated the part web ui part very easily with selenium but how we can automate that unix integration part with so that i can have my complete intuint test automation or there might be some some application let us say like which is processing your text file and let us say your you are preparing some text file and then you are sending the text file to your unix server so that unix shell script will process it and then you will verify the text file right so you can automate even this process with the help of this uh putty or ssh library okay so we will be talking about in next three to four videos we will talk about how we can automate it with approach one and and then we'll say approach two that is by using third party libraries okay so there are two approaches i can suggest you like by using putty tool but this is something which i can refer very less okay there is second approach which is by using ssh library okay so when i say putty tool okay so if you go to your installation directory if you go to your c drive and where where your putty installation is so my put installation is in windows program files and putty so here you can see multiple applications okay like the very first thing is uc putty which is my this particular application which i used to interact with the unix server then we have couple of more we have putty gen to generate my public private key then we have couple of applications like pscp psct and plink okay so by using these tool plink and pscp or psct we can do the processes like we can run the shell script automatically or we can schedule sftq operation for file transfer from uh to and fro okay so we can perform those things by using these tool and in next three videos i'll be talking about this approach one how we can automate these processes by using this putty tool so when i say putty tool that means by using this plink and pscp or psct okay so by using these tool how we can automate the various processes okay so that's what we will be talking so what and all processes we can automate it as i said we can let us say if you want to execute any command or any shell script or you want to execute any ftp commands file transfer from your local machine to server server to local machine or anything else if you want to type a file existing or something like that if you want to delete file any any kind of operations okay or finally to interact with any server for any other purposes so i'll be talking about these things uh in my next three to four videos for approach one and then i'll start with my approach two which is by using ssh library so i will use one ssh library for java which is jsch and by using that ssh library we'll see how we can automate all those all those processes internally and how it is more effective than using your putty tool okay so fine so stay tuned for this next video where i'm going to talk about how we can automate the processes using putty tools thank you hello welcome back in this video i'm going to talk on how to automate your shell script execution using putty okay so in my last video i have shown you a couple of putty tools okay so let me go to it once again so if i go to my putty installation directory okay so we have some putty tools in that like filling psdp and psdp so by using these tools we can automate uh few uh unix processes okay like your shell script execution file transfer and few other things okay so in this video i'm going to show you how we can execute a shell script automatically okay and how you can include it in your program okay um in your letters in java programming in linux so the very first thing is what i'm going to do is i'm going to create a batch file okay so you know batch file is uh ending with dot bat extension that is my batch file okay and the advantage of creating batch file is as soon as i double click uh in fact batch file is executable file as soon as i double click it starts its execution into command prompt okay so that's where i'm going to use my batch file okay and then okay now uh from this putty installation tools i'm going to use plink in this case okay because this plink uh okay i'll not be able to open plink like this like how i can use a putty but i can call this plink to execute my shell script excuse me to execute my shell script okay so i'm going to show you how we can do that so the very first thing is since i'm using this plink i need to change my okay and as i said we will be using uh uh command prompt okay so let us say if i navigate to my command prompt okay and if i if i need to use this uh if i need to use this particular plink then i should navigate to this particular directory so the very first thing what i'll do is i'll change my directory to this so this will be my first step in my batch file okay so that's what my first step is cd to put installation directory okay and then i will be using some command like this plink.exe okay followed by my username at the rate my server followed by shell script path so this is the standard syntax how you can execute your shell script using this plink okay and we will be adding all these things into the batch file so that as soon as i double click on my batch file or you can call even that batch file is your executable file you can call that batch file from anywhere and like from any programs and it will execute it okay so and we can finally once your batch file is created we can execute it from your java code or in fact since it is executable it can be called from any uh programming language fine now let us start so i'll be creating batch files so how we can create a batch file so you can simply create a text file okay and you can save the text file like i'm going to click on save it on desktop okay and let us say i'm naming it as uh shell exact okay i'm going to name it as shell exact and extension should be dot bat dot that is batch and since i'm i'm specifying extension in file name itself you need to enclose it with double code right so that it will consider this dot bat as a extension not this txt right so if i click on save you can see now my batch file is created so if i go on desktop we can see something shell exact okay you can see it is as a windows batch file so if i click on this uh the app can't run fine fine we'll see why it is not running let us create it first so uh now my i have created a batch file now my next thing is i need to change my directory to put the installation directory which is this one okay so i'll be using this command cd and this okay let me copy this and let me paste it over here now i'll get navigated to this particular installation directory okay and from this particular installation directory what i'm going to call i'm going to call filling dot exe that is this particular tool filling dot exe so that's why i after i navigate it to this i'll be able to execute this filling dot exe now in order to use this filling dot exe what i said is i need to specify filling followed by my username at the red server and my script file path okay so the very first thing is we will see my username okay so my username if you go here you can see not here let me go to put t so if you go to put t you can see my username as prakash p-r-a-k-a-s-h yes so i will add prakash at the rate what is my server so if i need to check my server i need to start a new session and basically i can get my server name from here okay so i will add my username at the rate server okay and then okay so i have given filling username server followed by script file path okay so i need to give my script file now so now i want to tell uh filling that i want to execute a shell script so i am using parameter hyphen s s h okay so shell script i'm going to execute shell script and now how to execute a shell script okay so let me go to my put me here let me close this and so let me do ls okay so if i do ls you can see some shell script over here that is script dot s h okay and how to execute the shell script is by using s h followed by script what is your script name okay so now you can see exec has started social execution it started right so since there is nothing in the script it will not execute anything but you can see execute started that is part of my script fine i'm going to terminate this execution so my execution is stopped fine so what what i just wanted to show you in order to run the shell script you will be using s h followed by your script name script dot s h now since my shell script was residing into my home directory itself i need not to give any uh directory uh location like how i have mentioned over here like go to etc then go to backup and then i have s h file present over here so if in in such a case i need to specify location as well but in my case it is present in my home directory itself so that's the reason i need not to give any uh location so what i've done i'm calling feeling.exe from this particular location then i'm passing my username on this server uh followed by ssh and my script now you must be wondering uh how it how it is going to authenticate okay so there are two ways how we it can authenticate by using password okay or by using key so in my case uh i'm going to authenticate with key okay but if you have password already handy with you then what you can do is you can use one parameter called as pw as an option and specify your password like just before username you need to pass this parameter as a pw and your password here you can specify your password here then followed by your username and whatever we have next right so the extra thing is you need to pass your password over here by using type and pw uh in my case i do not have password okay so in my case i have ssh key so if i have ssh key then i need to use a parameter called as type and i and then i need to pass my public private key okay so where is my key uh my key should be in my f drive key and here is my key which i'm going to use it to achieve the connection that's what i'm passing it from my venus city from my book i'm passing the same key so let me get this path for this particular key okay so fine now after parameter i i need to pass my key path right so that's what i'm going to pass okay so this is what my complete command is let me zoom it out okay so first i cd over here then i'm calling feeling by using this particular key i'm going to authenticate i need i don't need this password here okay by using this particular key uh i'm going to authenticate on this particular server with this username and i'm going to execute this specific command okay and after this i need to exit fine as soon as the execution is completed i need to exit so this is my complete shell script sorry complete batch file uh from which i'm i'm going to execute the particular shell script okay let me uh execute it now how we can execute i can just double click and it will start the execution and you can see it has uh ccd uh to this particular directory and then it has typed this particular command and it says access granted trace return to begin section now if i hit enter uh it is saying exact started that means my shell script execution is started but here you can see a manual intervention because it is asking me to press the return key okay so if i do not want this manual intervention then we can add one more parameter which is called as no anti spoof okay so what i can do is i can add another parameter uh i can add here or even i can add after your uh server and the parameter is no no anti spoof okay so that it will not ask you to um press return key as a confirmation okay so now i just saved it and i'll hit enter on this uh exact and now you should see the execution should start yeah now you see the execution is started i it do not have any manual intervention now and your shell script execution will start great so my shell script execution is started and now what i can do is basically now my shell script uh shell script execution uh basically batch file for shell script execution is completed by using this particular syntax and now i'm good to execute this batch file from my java code impact as i said this is a executable file windows batch file you can execute it from any programming language okay so in next uh next three videos i'm going to show you after three videos in fact i'm going to show you how we can execute any batch file from your java code okay so uh what next i'm going to do is i i'm going to call this particular shell script for this particular batch file from my uh java code so that i can uh include this into my automation framework okay so this is a part of in fact my approach one which i said i prefer less rather than uh i prefer uh using sss libraries like jsth for java or sssnet for csharp okay so fine so we'll continue with uh next video where we i'm i'm going to show you how we can do a file transfer from your windows to server from server to windows and post that i'll show you how we can execute this particular batch file from your java code okay so stay tuned thank you hello welcome back welcome to the course of linux for testers manual linux concepts and uh help automate all those linux concepts and linux processes uh in order to accommodate uh the processes various automation processes of linux in your test automation framework so uh as a part of this series i'm going to talk on uh automation of sending file to linux server using putty okay so as i said i have two approaches using putty tools and using uh sss library called jsh so using putty tool uh currently i'm talking on so here um for like in my last video i talked about how we can execute a shell script using uh p-link by using putty and here i'm going to talk on how we can send the file impact how we can transfer the file to and fro uh from linux server to your windows machine or or your local machine or from your local machine to your linux server via pscp which is a part of putty installation okay so the process remains same i need to create a batch file then i need to see cv to the putty installation directory then i'm going to use at this time if i go to my putty installation directory you can see something called as pscp okay so this is uh putty secure uh sptp uh protocol which is uh used to transfer your file as that that is your file transfer protocol for performing ftp operations okay so this p-link in last video i have shown you how we can do this p-link to execute the shell scripts uh in fact we can execute any commands by using this p-link and here i'm going to show you how we can do this pscp okay so i'm going to use this pscp and we need to use it in below format okay so this pscp and here i need to provide some options okay what are those options like uh uh could be my password or could be my um sshp or could be any options okay then i need to specify the source okay and then username post and my target okay so in this case since i'm sending it from my local machine to the unix server so my source will be my file from my local machine okay and my target would be uh any target into my uh unix server okay so let us start so let me go to uh this okay so this was the script from my last uh video where i have shown you how we can install ssh how we can execute ssh script by using batch file now i'm going to create a new ssh sorry new batch file how i can create i can create just a text file and i can go and i can click on save as and i will name it as send to host okay and the extension should be bad because it is a batch file you can look for my previous video for detail the description and i'm going to click on save and i'm going to paste my command from my previous video because i need to cc a cd to this particular directory where my put is installed and from this i'm going to use in fact this exe is not required uh so at this time i'll not give exe or even if we give there is no harm i can give pscp because we are going to use this pscp okay so i have i have cd to this particular directory and from there i'm going to execute pscp okay and this time our format is options okay so in options i need to give my uh option which is my uh public private key so here again we need to use parameter hyphen i fine along with hyphen i my p okay and then i need to specify my source okay so now what is my source so let us say let me go so let us say i want to send this particular file to my unix server okay so i can get the path of this particular file uh let me copy copy as a path okay and i need to specify path over here okay so i'm just uh space followed by path okay which is my source file so let us say i want to send this specific source file to uh host okay and uh followed by what next we have we have user adverite host so what is my user user is prakash so i'm just removing this unwanted spaces now user is prakash uh adverite host okay and this time um this no anti-scope is not required i believe or let it be because i think this anti-scope is uh i i mean uh why we use this anti-scope it was to get the read of that particular message like access granted press the return key to continue so i think we will not get this for acceptivity operation we get it when we use building if we get then we will add it fine now i have uh username adverite for my particular host and in host then i need to use uh in my host where i need to transfer my file so let us say in host i need to transfer my file to my directory called home slash praka so if i go to putty and if i do my print working directory you can see it is home slash praka so let us say here i want to transfer my file okay and my file name is file uh to send to host okay so let me just uh clear and let us do ls okay so here i do not see any file called as files into host.txt and so i'm sending this file from my local directory to unit server into this specific location specific directory okay so i hope this is pretty clear nothing much uh to talk uh cd to this putty installation directory from putty installation directory use this particular pscp for secure uh your file transfer operations type an i to pass my public private key then my source file the file which i need to send followed by my username adverite host followed by my path where i need to send it to my unit server followed by exit okay so now your question might be if you're not aware your question might be in which cases we might have this kind of uh we might meet this kind of operation so as i said earlier let us say you have a system where um your upstream system is sending uh extracts of your data this could be your data this could be your uh main frame files or could be anything okay let us say your upstream system is sending the extract of or in fact let us say let us call in simple terminology or in upstream system sending the files to your unit server and in your unit server uh you want to execute the shell script so that that particular file will get fixed process and it will generate one output file in fact it will do let us say some operations it will result some data that we need anything it will process the output file and you need to verify that output file so in my system testing what is my process what what and all i need i need to send this particular file to host then uh i have host in the sense to my unit server okay i need to send it to because sending receiving it from upstream system that is part of sit or or ui or uat whatever right but in my system testing case let us say i want to send it to my unit server for my for testing my shell script if it is perfect okay so i'll i'll be sending it to my unit server then let us say i'll be sending it by using this particular uh match file then i'll be my shell script by using the another patch script which we saw last time and then once the shell script is triggered for shell execution uh it will process it will produce let us say one output text file which i need to verify and in order to verify that file i can even verify it on a unit server but in order to do some operations on it like read it line by line and then verify then compare it with my results and all those stuff what i'll do is better i'll get it on my local machines in those cases we will download the file from my unit server to my local machine so in there could be any uh such as an arloot where you might need this okay so now i'm done with this i have saved it okay now let us run this particular script send file to host so i'm just double clicking it and you can see the script is triggered in your command form and now you can see the file transfer is successful there was some pop-up and i couldn't grab it actually but if you go to your putty now and if you do ls now you should see some file new file which is file to send to host now this particular file has been sent from your local machine to putty installation sorry uh unit server okay and the script which we use this this one by using pscp okay so this is how basically we can send the file from your local machine to unit server using putty basically using pscp so this is when we have a single file but even you can play along with multiple files as well like simply by using this file card you can do that let us say from this particular directory i want to send all the files with with dot uh doc extension or maybe you can you can give like dot dot sorry aesthetic dot aesthetic so that it will send all the files with all extension from the specific folder to the required directory where you want to send it so likewise we can send multiple files as well or even if you want you can add this multiple command into the same batch plane and you can take it so now your main task is you need to make these things parameterized like from where your key will be picked up or from where this particular file name will come here in your test automation framework you need to update it dynamically so that is something you need to take care okay so fine so that's what i have for this video in my next video i'm going to talk on how we can receive the file from unit server to my local machine using again putty okay so that's it so in again as i said in my next couple of videos i'm going to show you once we are done with creation of all this batch file how we can execute this batch files from java port okay so fine that's it thank you hello welcome back welcome to the course of Unix 4 testers manual on automation uh by bison selenium okay so uh in this video i'm going to show you how we can receive the file from unit server uh to your local machine using uh one of the putty tool called as pscq okay so in my last couple of videos i talked about how we can execute the shell script using putty automatically by creating a batch file and we can involve basically remove the batch file from any of the port then uh how to send the file to unit server and this video i'll talk about uh through the survey file so basically the steps are the same create a batch file then steady to put the installation directory and this time as well we'll be using this pscp but only this this syntax will change okay so what i'll do is i will just go and create another batch file okay i have copied the content because most of the things will remain the same i'm going to save it as a batch file okay on my desktop itself and i'm going to name it as receive from post okay something like that and my extension should be dot bat so then double quotes because i need to uh over read this dot a extension with batch fine now the very first thing is uh cd to putty then pscp again i'm going to use edges the format will change because i'm receiving it from unit server so the first thing will come your unix thing and then your local thing in my earlier video where i talked sending the files from local machine to host in that case the first point was sending the file that is from your local and then your unit server so the sequence was basically reversed in a sending case your local file will be first in the receiving case local file will be last right so it would be your uh let me modify this so in this case your this particular parameter will be at the same position just this file name should be last right and let us say from uh this particular directory uh foam slash precar i want to receive one file called as let us say this output file dot psd let us say i want to get this file so i need to give basically the complete path even we can use wildcard here to receive it in multiple files so we can see that so what i'm going to do here is uh using this key on this for this specific username for this server and the file from my unit server that is uh per class it should be slash so this output file from this particular directory will get received at this particular location pretty simple okay now what i'll do is simply i'm going to execute this receive file from host and you can see the process quickly now you can see the output file and you see something right if you want to just uh keep you can do is you can add one more line called as pause so that it will wait for you okay but although i have added pause and i'm going to run it again so here you can see the file has been received output file has been received the size is 0 kb let us say if in actual it is 0 kb so what i'm doing is i'll do ls iphone lpr and i'll check where is my output file output file is this let me uh check the content of my output file and i do have some content okay so i should see these contents uh i should see all these contents in the present in my file what is downloaded okay so i'll go to the location where it is downloaded and here it is you can see output file actual size is one kb actually okay and if i open this you can see the file is downloaded okay so this is what the contents are so these are the content which are downloaded here you can see right so this is how we can get the file from your unique server to my local machine and now what i can do is in my test automation framework uh if i want to let us say i want to validate this file then i can have some separate logic where i am going to read this file line by line i'm going to verify it so that that's my separate logic based on what i need so the basic thing where i want to show you how we can download a single file and how you can again receive a multiple file by using a wild card okay so again the same uh if you're not sure with the file name or if you want to receive all the files basically you can give a wild card so in this particular example it will go to this source directory in source directory any file which is starting sorry which is ending with dot p extension will get downloaded to this particular location which is my seed drive and source folder okay so if you want to download all the files from this source uh on from your unique server then you can give wild card dot wild card so that it will receive any file ending with any extension okay so that's pretty simple so now we are done with creating the batch files okay so in my next video i'll show you how we can uh execute these batch files and how you can incorporate uh them in your test automation framework okay so like double click will work now these are the batch files that they got converted into your executable executable file so you can call this executable from any uh programming language no matter whether it is java whether it is t-staff whether it is anything you are in in case of tutic as well you can call this in case of java with selenium you can call this in case of uh any selenium binding language you can call it or even if you want to execute it with toskka you can do that though uh toskka have one uh you might be aware about toskka test automation tool which is a stripless automation tool so if you're using a toskka which is a stripless automation tool which is bit costly in fact so if but if your organization have you can definitely go ahead with that and it simplifies these processes very much like they have one simple uh standard model uh for executing all this command you can simply enter the value and they will get all the things done for you but again the drawback is it is bit costly and if your organization afford it if they have it better you can go with that right otherwise again these things are also very simple nothing complex in that fine so that's it i have this video in my next video i'll show you how we can add files from my java code by using couple of options like forces builder and again one of the new thing which i saw which is plexus it is okay so that's it for this video thank you uh hello welcome back welcome to the course of inxmore testers so uh in this video i'm going to uh explain how we can execute the batch file from java code okay so in my last video i talked on how we can create a batch files like if i want to perform some operation like if i want to execute any unix command or if i want to execute any shell script okay or if i want to uh send any files to unix server or the 7a file so we can do all those things automatically from our code itself with the help of putty tools basically okay so we use p-link for running uh shell scripts and we use p-s-c-p to do s-s-p-p operations okay so basically if you uh you must have referred my previous videos for that so uh now let us say you want to do uh though uh now i have automated uh that particular operations from batch file now what your aim is your aim is to incorporate that particular thing like let us say executing shell script into your test automation framework so what i've done is i have created one java project okay so basically it's a mevan project and in my mevan project i have created one package called comjcs demo okay so okay basically i should create another package or let it be so in this package i'm going to create a new class and i'll name that class as exec using uh process builder okay now i'll talk on what is this process builder and all uh fine so i'm using this main class great now we have created the batch files as i said and if i want to incorporate uh execution of this batch file in my test automation framework then i like in this case i'm using java code but as i said since this is a windows batch file uh it is executable file so you can call it basically from any programming language or even you can call it from any scriptless test automation tools as well right because this is just a plain executable file fine now what i what i'm going to show you today is how you can execute that windows batch file from uh java code which you can incorporate in your test automation framework and basically we have two ways to do that the first way is using process builder okay and we have another way which i'm going to explain in my next video where we are using one api which gives us a good way to deal with command lines okay so now i'm going to show you how we can do it with process builder so process builder is basically a class in your java okay so the edit is basically used to uh perform execute the uh or to initiate various processes so the very first thing is you need to create the object of process builder class okay so if i just repeat that you can see process builder it belongs to java.lang okay so i am using the builder and i'm creating the object called as pb is equal to new and it should be process new process builder string command fine so i'm using okay let's take a new process builder and here i need to give me basically the location of my batch file okay so in my case i have my uh okay so here it is let us say if i want to if i want to send particular files to host okay so i'm going to use this particular uh batch file okay and how you can get location for this batch file i can go to properties i can either get this full location okay or i can get this location only and then i can use uh system dot get properties right so let us say if i want to get the location of my current project and then i from my current project location i can navigate to this particular path okay that's what i'm going to do okay so if you want to get the current location of your project then you can use system dot get you should have something get property yes and the property to get your uh location is user dot dir it is to use get user directory now i am into this particular directory let us end and from this directory i need to navigate through this steps till this particular location wherever i want okay so i'm using class okay and now i want to navigate so i've just copied the location and i should use double slash right because it acts as a skip character fine now i have created the object for your process builder class okay now what next i should start the process so if i use pb dot and i should see one option as start okay and here you can read the basically description is to start the new process using the attribute of this process builder so i have created the process builder and i'm going to start my process by using this pb dot start okay so if i execute this simple line two lines of code it will work perfectly no issues okay but now what i want to do is i want to uh check if my execution is successful what is the written code what is the output that i'm expecting on my console uh or your terminal whatever it so in order to do that uh we need to uh get it basically in the process object so if i hover my mouse on start you can see it returns the process object okay so what i'll do i'll i'll uh use process object it is again from the same package and i will name it as process equal to pb dot start now i got this process object okay so by using this process object what i can do is i can get the input stream that is uh the data which gets on your terminal and basically i can get the exit code okay if my exit code is zero then the execution is successful if it is not then there is a mission fine now my process is started and i have uh send it to some process variable okay so what i can do is i can use process dot okay so if we do just process dot dot you can see some uh uh methods in it like get input stream and you can see the description for get input stream is it returns the input stream connected to normal output of your sub process okay so what basically this get input stream is whenever you run any process it will display some it will write some content on your console or on your terminal so in order to read that content we will be using this get input stream again we will be using this wait for okay so this wait for is used you can see it causes the current thread to wait it necessarily wait until the process is uh terminated okay so we will be using this process for as well and by sorry wait for as well and by using this wait for we will be waiting for my process to get completed and get the return code okay or exit code whatever okay so the very first thing is what i'll do is i will get this input stream okay and i'll just displayed on my uh this particular console over here right so i'm trying to get my input stream now uh okay what this get input stream return it returns input stream okay so i need to basically assign it to input stream okay so what i'll do is i'll use new input stream okay new input stream and okay so process dot input stream fine okay so basically we should use uh input stream reader yeah so we'll be using input stream reader to read the content and where we will be storing those content we will be storing those content into a buffer reader okay so i will create one object of buffer reader class buffered reader uh bf is equal to new buffered reader and i need to pass the reader okay and what is my reader my reader is basically this particular input stream excuse me so now what will happen is we we are using the process object to get set input stream this get input stream returns uh input stream reader okay and by using this input stream we are storing the content of that input stream into my buffer variable which is bf okay now or even i'll let me call it as reader okay so i'm going to store the content into the reader now what i'm going to check is i'm going to read the values from reader okay so to read the values from reader what we can do is we can use that object of reader and you can see the method called as read line okay so basically we can use this object read line okay and what i'm going to do is i'm assigning it to some string line is equal to let me define some string so what i will do is i will use while loop over here so that i can iterate over all the uh what i can say all the lines of text which is present into my buffer reader and i will check if my line is not equal to null if it is not equal to null then i want to display it okay okay now if it is not equal to null then i want to display it okay i can use okay or else what i'll do is uh okay i can basically one uh string builder okay so what i'll do is i'll create one string builder so string builder is basically a mutable string and what i will do is i will append uh the data to string builder okay my data is present in line okay and then uh i need to add a line separator okay so i'm going to do it so that my next line will get displayed onto the uh next line in my uh string buffer string builder sorry okay so now i'll have my all data into this specific string builder okay which is my sd now what next fine so what i can do is i can simply display system.out.println sd that is my content from string builder okay so oh god this command over here not required fine so now if i execute this code simply it will uh it should execute the code but before i execute the code let me connect to my putty and let me check what file i'm going to send it to my unit server okay so basically uh in my particular batch file i have i'm trying to send this file file to send to ghost and the file is already present over there let me delete that file okay now that file is deleted great now what i'll do is i'll simply execute the code and we'll see if it works okay so you can see uh my execution is successful and you can see the the things which uh which get compound on your terminal are already displaying over here that is because of this particular reader and this particular part otherwise if you just want to trigger the process these two lines are enough and if i do a list now i should see that particular file here but why don't i see okay let us let us what we'll do is we'll try and get the exit code if my exit code is zero that means my execution uh particular process is successful so what i'll do is i'll use process object dot we have some command called wait for that i have already explained okay and just wait for what it returns if you just hover your mouse on it uh in a second it returns an integer okay so i'll try and get int of a return code is equal to this okay and what we'll do is if we'll just check the code if my return code is equal to zero then this thing else i'll print something not successful now let us do it again okay so this particular part is getting executed that means my execution is successful because i'm printing that particular part then my return code is zero okay so now let me go to this particular file okay so basically uh my file what i'm executing i'm okay so actually i was using this receive file from host so i should use this send file to host okay so now it should work i was referring uh some different batch file okay so you can see uh i i didn't get any error messages like not successful or any other error message that means my execution is successful and if i do ls over here now you can see my file has been sent to host okay so this is my right okay so this is how you can execute any batch file from your uh java program uh let us let us let us try and run another batch file which is my run putty okay so okay so in my run putty okay let me show you the script what it has okay so in run putty basically uh the script is of three lines only so we are using pre-link to execute my script which is script.sh okay and i'll show you what is there in script.sh okay so if i do ls over here you can see one script called as script.sh okay so uh okay uh let let me show you the content of your script so my script content is something like this i'm just doing something and what i'm trying to do here is okay so i'm trying to read some data from input file and i'm going to write the data into file called as output file so i'm basically doing the read and write operation okay so that's fine i'll explain this uh shell script in another video uh so i'm going to terminate over here so this is my shell script basically okay so if i execute this shell script from over here like ss dot script then you can see uh shell script to read and output uh text file and the file process has been completed that means my shell script is executed successfully and it has generated your file called as output file by reading my input file file so this is how it will execute now i'm trying to execute the same script this script.sh from this specific batch file why am i java program so i'll just run my java program okay and you can see file process has been completed let me uh let me do okay so what i'll do is i'll just delete this output file so that you can see uh if my okay now my output file is not there now you don't see anything called as output file now this output file will get generated as soon as my shell script execution is completed now what i'll do is i'll execute the script okay my execution is completed and i should see the file called as output file so here it is so this is how basically we can use uh this process builder class to execute any batch file okay uh fine so you can incorporate basically this piece of code wherever you want to execute any batch file uh and in the batch file we have something we call up putty tools and execute our uh desired unix processes whatever we want to do fine now in my next video i'm going to show you how we can achieve the same thing by using uh another java api which is called as plexus utils okay so we are going to achieve the similar thing uh by using another api okay so thank you hello there welcome back welcome to the course of unix foretest source manual and automation in this video i'm going to show you how we can execute the batch file a batch script that is your windows batch file from java code with the help of a java api called as plexus utils in my last video i have shown you the same thing with the help of process builder which we used by default but this is something uh makes our life a little easier if i use this plexus utils but for this uh for using this plexus utils you need to uh add one dependency okay so i'll be showing you these things now so uh okay let me go to eclipse and let me create another class called as exact using plexus util and i want the main method uh fine let me remove these unwanted comments great now what i want i am i'm going to use plexus plexus utils okay so this is one dependency one java api in fact which we will be using so if i just go to google and plexus utils okay so you can see uh basically this plexus is from code house okay and if i go to this main one repository uh basically i'll be using this dependency from main one repository okay and it is from or the dot code house dot plexus okay so i'm getting this latest dependency 3.2.1 okay since i already have it let me check which version i had it uh so i'll go to my palm dot xml so if you do not have a main one project you need to download it and import it in your java build path but since i have a main one project what i'm going to do it i have used this dependency 3.0.24 but maybe you can use the latest one that should work so i what you can do is you can just go to the latest just copy this code and just paste it in your dependencies it will get a dependency for you and if i go to main one dependencies i should see plexus utils uh the respective respective version which i selected okay if you are not using a main one dependency you can just download it and then uh you can just download it from here jar and then you can import it in your java build path fine now i already have it so i'm not going to do that again great now let me start so uh to use uh okay so the plexus is basically to uh if you want to use with command line tools or i o tools then basically this plexus utils is going to help you okay and in this plexus we have some method called as command line okay so this is something which we will be using and it is from oarji.codas.plexus.util.cli okay and you can see the description here command line object command so i'm going to use this command line and cmd creating object for it new command line fine i've just created the object of command line class okay and then by using this cmd object what i can do is i can set the executable what i want to execute okay so if i just hit cmd. you can see some method like set executable create arguments set working directory if you want to just change your directory you can do with this why i simply want to set my executable because i already have a jar file okay and what is my executable my executable is let us say i want to execute this uh run put t okay so what i can do is i can okay i'm just going to my last code and i'm just copying it from here so we'll be using system.get properties and my irrespective batch file here let me copy this and i'm adding it as my executable great now i have set my executable okay so fine now if i use uh give me a second okay sorry yeah so we we just did a set executable okay this is something which i want to execute but we didn't started the actual execution now so to start your actual execution we have something called as another class which is my command line utils okay so i'm going to use this command line utils okay and if i do command line utils dot then you see something like execute command line okay so you see uh different overloaded method just let me expand this you see different overloaded methods so execute command lines have this five to six different methods sorry this class has different five to six method and you can see some uh like the very first argument is very very much common your command line cl and then next we have some input stream or we have your stream reader or something like that okay so let me check which i can use and you must notice all methods have written type as excuse me integer okay so basically i'm going to use the very first one and why i'll tell you okay so the very first one what is my command line i want to execute my command line as cmd okay and why i picked this because i wanted to get my system output whatever the output is going to print on the console or a terminal that is what i want to get in this system output and in system error in case of any error if my command is not found or if there is any issue then all those things i'll be passing in this system error but in order to pass this i should create object of them okay so to create the object of create object system out i should use uh a write stream consumer okay so let me second okay so we have one class called as write stream consumer i'm going to create object of it write stream consumer okay is equal to new write stream consumer and i need to give some writer okay so what is my writer i am going to create a new stream writer give me second i am looking for stream writer okay so basically that would be output stream writer okay so output stream writer and uh what i want to get output from so it would be from system dot out it will print my stream fine so now i got one object which is my uh system out with the help of class writer stream consumer so this will basically uh print it on my my console basically or i can get it in my uh what i can say i can get the text from it and i can use it in my program if i want next is my system error okay so what is system error in case of any error okay so how i can get it so again i'm going to use uh what i have uh okay so basically see two things system out and system error so if i execute any command on my terminal let us say so i'll get my output as well on this terminal itself and if any error then i'll get that error itself in the same terminal okay so basically i can use this system dot out itself for my system error as well okay so i'm just doing going to do a copy paste and assigning it to a object called as system error and that's done right now this will execute my command okay and uh what is written type so it's written type you can see its written type is integer okay so what i'll do is i will just get written type integer uh in my let us say written code okay so now i got the written code over here and if my written code is zero that means my execution is successful if not then there is an issue okay so i can use if written code is equal to zero then i'll print something successful with zero written code and in case of any issues i'll print them in else part okay so basically i'll just copy paste this and my execution will be unsuccessful and my written code would be non-zero okay so that's pretty simple what we did is we just created a reference of object reference for this command line which is the base class from where we are going to start and then to this cmd we are going to uh like i have just set my executable okay if you want to change the directory we have a method for that i just wanted to set my executable directly because i do have a batch file which is directly executable and then to read the content from my terminal i'm using like in case of normal system dot out in case of error i'm using system dot error those two things i need to pass to this uh execute command line methods uh under command line here okay so uh so and this particular execute command line method which is from command line utils returns uh an integer if that particular integer value is equal to zero that means your execution successful if not then you have some error let me execute this and okay you can see the execution is successful zero code and you can see whatever i had printed it in my command shell uh shell script it is getting printed so that means the execution is successful great so now uh you can just embed uh this this much lines of code anywhere in your test automation framework wherever you want to execute any batch file okay so this is how basically we can run the batch file and in my batch file i have the code i have some code which interact with my unix server right but now uh okay so now uh earlier as well i might have talked like uh i'm i'm going to tell you two approaches the first approach to do the automation of unix uh processes is with the help of putt and another one is with the help of and java api called jsch okay there are n number of apis for java for other other technologies as well for cshap we have for other as well we have uh but the drawback of using this particular uh batch file this batch file because in the batch file what we used in the batch file we have let me open the batch file in the batch file basically we have used something called as pscp.exe or pilling.exe okay uh so uh wherever you want to run this specific test automation framework if and if you are using this particular line of code then you should have this pscp with which is basically put you to install at this specific location whatever you will mention over here so if you are trying to execute this particular code in your test automation framework from uh let us say from jenkin server uh in your jenkin servers as well you should have putt installed and you should location of putt over here the same location what you have in your jenkin server okay on the machine where your jenkin server is installed so that is a prerequisite basically requisite uh for using this particular approach okay so and the second approach what i have is by using uh java api okay so since i'm using java in this case i'm going to use java api but if you are using c-sharp then you can use another api which are available in c-sharp which i'm going to show in my next video so if we're going to follow that approach this particular dependency gets removed because we do not interact with unique server via uh via any uh ssh client like putt okay we do the direct interaction okay and how do how we do that i'm going to talk in next four to five videos okay so it depends on uh your uh your your way where you you want to execute your test automation framework in some organization ssh uh java api for ssh client they do not permit they only permit using this putt so for them this is the way how they how they can do this otherwise if your organization permit you to use another uh third third party api like jsch which you are used to interact with uh unique server from your machine then that's the best approach we should go ahead with okay so that's it from this video so from next video i'll be talking about uh my second approach uh by using jsh okay so yeah that's it thank you come back welcome to the course of Unix for testers some manual and automated processes which can be clubbed along with any test work like selenium uh in this video i'm going to show you in fact talk about uh what are the various libraries available to automate unix testing so in my last four to five videos i talked about how we can create a batch file and how we can execute that batch file by using java code that is by using process builder and another java api okay so that is one way how we can automate the unix processes the various processes like sending the file to your unique server executing any unix command are receiving the file from your unix server to your local machine for some purpose and executing your shell script which is most important functionality within unix so that's the one way but in my last video i must have talked about excuse me drawback of why we may not use uh that that approach using sftp sorry uh or using putty tools because it need to have put installed on that particular machine where you want to run that run those specific test cases uh the another approach is to use a set of libraries various libraries which we have okay to automate all those processes and in this video i'm going to talk about two libraries uh basically uh for two languages so the first one is for java clients okay so the java you must be close to like maybe more than 80 person people for seven minute java so that's the reason i pick java library for automating this unix testing but in fact we can use uh like we have the ssh client for your c-sharp you can you have a ssh client for pipeline maybe you can have this particular ssh client and you can use them to achieve the similar things so what are the different java clients available uh for java what are the different libraries available for java to achieve these ssh things the very first one is your jsh and this is the one which we are going to use as a part of this particular course to automate all our uh unix processes and i'm going to show you how we can uh use it in your selenium test for promotion framework so the various other libraries are ssh j sshd common vfs then we have gandmaid ssh too but out of jsh is preferred more as compared to other tools moreover if you know uh how you can use one library the functionality of other libraries are a little bit same just they might have some different method name different classes different uh parameters and few other things so uh jsh is something which we are going to use which is a java client now if we talk about c-sharp clients for c-sharp as well we have ssh clients okay and the very first one is ssh net and we have another popular which is sharp ssh sort of that ssh net is bit popular as compared to this app sharp ssh so i should give a preference you should give in fact reference to this ssh net okay in fact if you talk about like we have one scriptless automation tool called uh toskata suit and they have given some standard models to interact with like they have already given standard models to automate all those things and in back end they have used uh this ssh net uh which is a c-sharp client because toskata is already built on c-sharp so they have they have used this ssh net okay now uh let us talk about this ssh net okay sorry ssh okay so if i google jsh so the very first uh url you see from jcrap who is the owner of this particular library okay and here you can see jsh which is a java secure channel okay to perform the areas operations and here you can see the applications which are using jsh like your eclipse itself is using jsh net bin is using jsh then your hp g-write itself is using your jsh and there might be many other who are using already using this j plant okay so now two things if you want to uh if you already have a mevan project then you can uh you you can go to mevan repository and get dependencies from there if you do not have you can download uh the jar from here you can directly click on here and it will get a jar downloaded to you but if you have a mevan project you can just go to uh or what i'll do is i'll jsh mevan dependency it will work for me jsh mevan dependency the very first url i got is com.jcraft jsh and the latest one is on dated November 2018 that means it is quite up to date not very much up to date but it is okay it is up to date okay so i'm going to prefer this latest version 1 0.1.55 and we will be using this dependency in our uh project which we will be talking from our next uh video okay so so this took up from all these processes like execute any unix command could be a very simple starting from your ls to get list of all the uh things in your particular directory could be your source functionality grape or any kind of command uh and that could be your sending file to your unix server receiving file executing your shell script checking a particular file exists onto your unique server at particular location could be uploading downloading multiple files to your unique server to alpha okay so all those things we are going to achieve with the help of this particular jsh library okay that's what we will be talking uh that's what i'll be continuing in my next five to six videos these things how we can automatically so that's it i have for this video stay tuned thank you hello welcome back welcome to the course of phoenix for the source manual and automated uh so in this video i'm going to show you how we can use basically uh jsh in your java project so the language binding which i uh chosen over here is shava okay so that's the reason i'm using jsh okay so i'm going to show you how we can basically we we must be knowing everyone how we can create a java new one project and then i'll show you how we can get this jsh mevan dependency so if you're using a mevan project then you can use basically the mevan dependency if you are if you are using non-mevan project then you can download the jsh jar and then you can add it in your build path okay so i have already created uh basically the mevan project so i'm not going to create a new one but i can just show you how we can do that click on file i'm basically using eclipse eclipse ide okay and the process must be common in uh almost all the idea whether it is eclipse idea whether it is net bin or it can be your ad so i'm going to file click on new then i'm seeing the very first option as mevan project if you don't see over here then go to other and search over here for mevan okay so you should see option called as mevan project if you don't see you might need to install the mevan add-in so you can get it from help and install software or eclipse marketplace you can send you can find both the options you can get it from there uh so i've selected mevan project okay and you can select the location basically so i can select my location as eclipse workspace great and i want to sing uh fine and i'm going to click on next so from here you can select the the archetype basically this archetype gives you the structure of your project and here you can just enter your group id and artifact id from where your project will get some name okay so yeah so basically i'll enter let us say group ideas come and then artifact id as let us say my project id basically which is let us say demo and dot if i want to enter anything that i can enter something something okay so like this okay and version could be a basic version or you can give like version one or version two it could so this version is basically used when you are packaging your jar but in our case packaging is not required so we can leave it as it is and you can just click on finish it will create a mevan project for you i'm not going to create i already have it so the basic thing of mevan project is your palm dot XML okay so in your palm dot XML we will be adding the dependencies for jsh okay so in order to use this jsh i need to download that particular jar in my project so that's that is something which i can get it from mevan dependency if i have a mevan project okay so i can just do something like jsh mevan dependency okay and the very first link i'll get it as mevan from mevan repository and the version i can select in fact we can select the latest version let me check which version i have selected the version i selected is 1.55 and yeah that's the latest one okay so you can just copy this dependency and test it in your palm dot XML under dependencies tag okay so this dependencies tag is your basic base tag under which you have dependency closing tag dependency so you can have multiple dependency under dependencies tag fine so now once you add your dependency you can just click on save it will download the dependencies for you and you will find something called as mevan repository over here and you will find the jar will get downloaded in your dependencies it is having various packages so if you do not have a mevan project what you can do is you can go to the same site you can just click on the jar file over here it will download the jar file for you and you can just go to your project and build path configure build path and you can add your jar files okay so you can go to libraries add external jars and you can select your jars and you can add it your project will pick them thanks so basically this is what we need as a dependency now next fine so we have created we have added a mevan dependency and we have downloaded the jar now what next I'm going to show you one example okay how we can use the jsh for interacting with basically your unix server okay and then we have like I'm going to talk about multiple examples like how to upload file to unix server download files how to check if file exists how to execute any unix or unix command onto the server or shell script onto the server will I'm going to show you many things okay so stay tuned for this thank you okay so let's get started with jsh and the very first thing when we are since we are talking about the communication between your local machine to your unix or linux server right so there should be some authentication method whenever I try to interact with my unix or linux server there should be some authentication there should be some key or there should be some password or any any other way right so that's what I'm going to show you how we can use it in when when we use jsh so now why authentication because as I said since we since we are interacting with the server there could be a linux server or linux server only a person should interact should be able to communicate with the specific server so that's the reason there is something called as authentication and we have various methods to use authentication the two which I'm going to talk is we have something called as private key and we have another one called as username and password okay so let me go to my eclipse and let us create a new class and let me call the class as execute any command on unix or could be your linux basically the processes are same unix server using jsh okay so this name is a bit long we should not refer the name as this much long but since I'm doing it for demo purpose the name isn't true so that's the reason I'm putting it great I have created a class and I have a main method in now what I'm going to use is I'm going to use jsh which is my ssh client java ssh client basically which I'm going to use to interact with my unix or linux server okay and if you see the main dependency jsh you can see some package called as jsh okay so basically it must be having some methods like okay so in this particular demo I'm going to talk about what is channel what is session then what is jsh basically okay so this jsh class is something which is my starting point okay so I am going to create an object of jsh class okay so you can see it is coming from the same package which I just opened and jsh and I'll call the name as jsh is equal to new jsh great now I have created the object reference for this jsh package uh sorry class great now this this is basically my starting point to enter into this process now if I use this jsh dot okay if I use this reference you can see some methods which I can use like get session the very first method and you can read the description it is used to instantiate the session object with a given username host and port note that the tcp connection must not be established until session dot connect fine so what it is saying is we can use this particular get session method so step to set the connection basically okay and we can pass username host and port okay but until and unless we do session dot connect actual session will not get started okay so we will be passing three parameters to it basically username host and port the other methods which we will be using is add identity the add identity method you can see the description it is used to set the private key okay and yes I believe you're watching my earlier videos and you must be knowing I'm using private key to establish my connection not a password okay so okay so let me use this get session okay and now what is my username okay so my username let me open my ssh putty sorry and in my putty let me get my server name as well my host name basically okay so let me connect okay so my host name I am putting my host name as my ip basically okay and port the default port which is double two and now I want my username so basically my username is prakash okay and you can see whenever I log in it says authenticating with public key as prakash okay so my username is basically prakash fine so now I have created a session so if I use this okay let me throw that exception js is exception fine now if I hover my mouse you can see this get session method written your object as object of session okay so let me create object of session then session session is equal to let me import this session from again from the same package fine now I have created a session so basically the flow goes like this so you have created the object of jsh class which is the entry point then by taking the reference of jsh I'm creating the session okay and from this session I am going to create a channel okay but before we go ahead with channel now we need to do something with setting my password or setting my key basically okay so how we can do that okay so if I do session dot let us see what an all method it has it has a method called as disconnect it has a method called connect so these two methods are self-explanatory connect and disconnect to connect and disconnect my session then we have something called as open channel okay so this method we will be using in order to establish the channels okay so the flow is first jsh object then create session using jsh object then by using the session object create the open the channel basically with various your object use it could be your sptp operation it could be your exec it could be anything other we will be seeing that then the next is set password okay so this basically the set password session dot set password we will be using it in order to if I have a connection method with username and password okay if my particular unique server or Linux server need password in order to authentication in order to do the authentication then I'll be using this session dot set password okay but in my case since I'm using the key basically I do not need this session dot set password okay so what I need basically is I'm basically using the key okay so you can see this is my key okay even if I edit you can see that there is some key okay I'm basically using this particular key okay so in order to use this key let me create an variable for this string private key path is equal to and let me get a path for this particular key because I'm going to use this particular key okay and fine now I should use sorry double slash now I have I'll be using basically this key with the help of this particular variable okay and we should pass this particular key to your jsh object so if you see jsh then you see something called as add identity and task to to set a private key so this is how we will be setting the key to my particular ssh object and which will be inherited by your session and channel you know while while while establishing the session this key particular key will be used great now we are done with creating the session not establishing just creating a session then by setting since setting password is not required because I'm not using password so that's the reason we added identity for your private key path okay and okay so there is okay so if you need to pass any properties okay if you need to pass any properties to your what I guess is session then basically we have some method called as session dot you should have something called as that okay yeah we have session dot set config okay so we have something called as session dot set config and you can pass the values with either you can pass a value of key and pair sorry key value pair or you can pass the properties file okay so I am going to pass a value for properties file and what value I'm going to pass is so for that let me create one instance of properties properties config is equal to new properties okay and in this property is what I'm going to put is config dot we should have some method called put yeah fine and then here I'm going to add a value here a key value pair basically okay so my key is strict host key checking I should give the value as no okay and why we need this I'll tell you okay so sometime what happens is even if you are setting the password from here or you are setting a private key from here it might ask you for a password in your command prompt whenever you whenever it's create a session before before in fact before it create a session okay so that's the reason we are asking to strict give me a second should this strict strict host key checking and I'm setting it to no and basically I should pass this config to set config here right so this is how we can configure the session here if that there there could be n number of properties which we can get and you can find the details on the website of jsh okay so you can refer this website it's their official website jcraft okay so you can see some examples over here some examples over here and wiki okay basically you can explore this particular their homepage you can see some examples as well over here okay so that's fine so now I have uh set this particular uh configuration file and now I should be good to establish my session session dot I should see some methods as connect great now I should be able to get connected with my Unix or Linux server okay I'm just trying to click on the run and so now I will not understand if my session is successful I can expect some exception if anything but I do not expect anything to be printed on this console okay so I'm assuming it is connected because we didn't use session dot disconnected okay because otherwise it will keep the session connected continuously session dot disconnect okay so let me put some thread dot sleep okay so you can see the execution is started let us say and it should get disconnected let us say after three seconds yeah it got disconnected now so I am able to basically authenticate by using my private key and my particular details my post name and my username okay so that's it I wanted to cover in this particular video in my next video I will explain the further processing how we execute how we can execute basically any command in jsh and which we can incorporate in your test automation okay so stay tuned thank you hello welcome back welcome to the course of Unix for testers Unix manual concepts and how we can automate all those Unix manual concepts which are required for basically testing purpose and we can incorporate them in your test automation framework so in this video I am going to talk on execute any Unix command via jsh yeah basically that's in your test that is something which you can incorporate in your test automation framework okay so what I'm going to talk is how to create authentication I have already talked in my previous video you can refer my last video we have created a session basically okay and we have connected a session in my last video so till that we covered now in this video I'm going to cover about how we can create a channel then how we can execute a command and how we can get the output of basically that executed command and I can verify it basically okay so let us switch to my eclipse now this is what we saw last time now let me remove this session dot disconnect and thread dot slip now once my session is connected okay and if I check what an all object I have sorry methods I have in my session so the very second one you can see open channel okay so at a session dot open channel so now I'm going to create a channel okay so now what kind of operation I'm going to perform over here right so let us say if I open this open channel method and fine so basically what I'm trying to perform the operation over here is I'm trying to execute the command okay so the type of channel for which I'm opening it is exact if if you want to do it for to do sftp operations file transfer operations then basically we'll be using sftp over there but in this case I want to perform exact operations right and if I hover my mouse you can see it returns a channel so let me create an object for channel and assign it to channel channel is equal to session dot open channel now I have created a channel now I'm good to execute my command okay so if I now if I use this channel channel object and what an all methods I have I can see something like disconnect basically connect and disconnect to so so we have two things sessions and channels okay so initially I'll set the sessions I'll connect to the sessions then I'll connect to the channel then I'll disconnect to the channel and then disconnect to the session so then we have something called as get input stream get output stream it's closed and we should see something okay we have another one called as get exit code to basically get the written code what is my output of my current operations which I'm which which I'm just doing basically we should have some set operation set okay so basically what we should do is we should cast this channel with channel exact because we are forcing it right so we should give me a second channel exact yeah so and let me import it let me import it I should get some option of the import give me a second okay so let me import it explicitly so let me copy this channel and I'm trying to import channel exec okay so if you see this jsh packet you should see something called as channel exec so here it is channel exec so this is the class which I'm going to use now okay so channel exact yeah so and whenever I'll be doing saptp operations file transfer operation I'll be casting it with channel saptp so in this case I'm going to use channel exec fine now I should not see that error okay let us check with if I can see yeah now I can see the method with set command okay and basically here I'm going to pass my command okay the command which I want to execute okay so let us say I want to simply execute my command as ls to get the list of files basically list of items in my present directory okay so fine now fine so now I'm done I'm I'm just I've just set the command now I am I'm good to disconnect my channel channel dot disconnect and I should be able to disconnect my session great now and if I run this okay so something has happened okay something has happened but I don't get my end okay so that's fine now okay let me show you something practically so if I go to ls-l okay so you can see something like okay so you can find my f1 file and the permission for f1 file is all are hyphen right so what I what I'm going to do is now I'm going to set a permission for this f1 and I'm going to set it all 777 permissions okay so the command which I'm going to execute over here is and the command to set the permission is you must have referred my earlier video is ch mode and I'm going to set up permission as 777 that is all the permission and my file name is f1 dot txt okay so if I execute this command now and if I do ls again I should see this permissions of this particular file f1 should have been changed to read write execute okay so now I can see the operation is completed and if I do ls hyphen l okay so you can see it is not done that means there is some issue okay let me check if the file name is correct it is f1 dot txt f1 dot txt is ch mode fine okay let us check uh okay so what we did is we just created a session and we are directly trying to disconnect a channel but we didn't create we didn't connect it to the channel yet so basically I should use channel dot connect okay and now if I see okay the operation is completed and if I do ls hyphen l again now this time can you see the the permissions for f1 it changed to rwx rwx and rwx right so that means whatever command I'm trying to execute it from here I'm able to execute it it is getting executed successfully in my Unix or Linux environment fantastic this is what I was looking for great now what next but in my terminal I'm not able to see any output right let us say like how will I get to know okay we have something like channel dot get exit status we have something like channel dot get exit status from this we can get to know if my execution is successful or not this is one way or what we can do is I can read the console basically okay I can read the console and I can check if my execution is successful or let us see if I'm trying to execute on a shell script then my shell script will print something right on my console basically so let us see if I want to verify that particular part of my console then what I can do is then in that case I need to read my basically the stream streaming messages okay so how I can do that let us let us do that okay so the similar thing which I did in my video where I talked about how you can execute a batch file so there should be something similar like that okay so the very first thing is I should get the input stream from my channel okay and where I'm creating my channel I'm creating my channel over here right so if I use channel dot get input stream it should return me some input stream okay and the written type for this is input stream okay so let me create it input stream in is equal to what's wrong okay yeah input stream in is equal to channel dot get input stream basically this will read my this will help me to get the messages from my channel whatever messages I'm getting into the channel I can get it now I need to use this particular I need to read this stream as well okay so once my channel is connected okay what I'm going to do is I'm going to read that particular messages by using input stream reader stream reader can I say somewhere input stream reader yeah and basically it needs your input stream my input stream variable is in okay so what what it returns input stream reader okay and what I can do is basically I can pass this input stream reader to my buffered reader where I am going to store my all the messages okay forward reader yeah buffered reader and my reader is basically my new input stream reader great fine and what this buffered reader return it returns my buffered reader where I can create its object buffered reader reader is equal to this now I should get all my messages which I'm reading it from input stream into this particular reader okay and how how I can read it from reader that I have already explained okay so what I can do is I can use reader dot read line this will basically give me give me the content line by line okay so what I'll do is first I'll create one string call line string line okay and what I can do is basically I can use a while loop okay while because I want to do it till my okay till it is not null okay so what I can do is while it is not null as not equal to null okay if it is not null what I want to do is let us say I want to print it I want to print my line okay and I can do that fine now this time what I'll do is I will execute to ls and I'll check if it works if it prints great it is printing it for me right if I want it in more sophisticated way what I can do is I can use ls add tia that will give me little more details excellent I'm able to read all the contents from my terminal okay now if you want to verify this particular content if let us see if you want to verify if a particular file is there or if what are particular operations sorry what are the different rights or permissions for a particular file has if you want to do some verification then what you need to do is you need to store basically it in some list store in some list okay so what you can do is you can store the content of this line into the list and then you can iterate over that list and you can verify it okay that is something how you can handle it again great now let us let me write some wrong command okay so I'm using ls0 which is not correct let me check if I can get a error message over here okay so what is happening is if I'm passing incorrect command okay so I'm expecting message like if I give something like ls0 I should see some message as bash ls0 command not found but here I'm not getting that particular message okay so what I can do is we can set the channel again with some error stream okay so here we used channel dot get input stream okay so the same channel what I can do is okay what I can do is I can set I can set channel error stream and what error I'm expecting the error form system dot error great now I should see the messages in fact this casting is not required this time because we already did once okay can you see the message now command not found great that is what I was looking for now so this is how basically you can execute any command so as I said if you want to verify anything what you can do is you can create a list I release and you can add all the message into the array list before you disconnect and then you can verify the content of list whatever you want basically okay so that's how you can execute any command basically on the Unix server using jsch which is a java ssh client okay so that's what objective of my particular video was okay so what you can do is you can basically uh incorporate it uh incorporate this particular code into your test automation framework to do whatever you want basically okay so most of the time it might not need to execute any command in automation but what we need is mostly we need how you can execute the shell script or how you can send the file to host or receive file from also those things mostly we work with we deal with okay so I'm going to talk about those things in my next video so stay tuned thank you hello welcome back welcome to the course of Unix 4 tester in this video I'm going to talk about how you can send or upload the file to Unix server from your local machine let us say okay so assume a situation in your a test automation project where you want to upload some file to the Unix server your shell script will run on the Unix server which picks up the file which you have just uploaded and yeah basically it will process and it will do some operation could be that could be db insert or could be producing another file or could be sending a lot somewhere could be anything right so basically what you want to do is you want to send the file so that let us say my shell script will pick could be an example okay so this is just what I said so how we can achieve this using jhsh api which I'm about talking from my last two sessions so the very first thing is creating authentication that is again same as how we did in my last two videos again creating channel that is again going to be same so let me jump to my eclipse quickly and let me create one class okay or rather what I'll do is I'll simply copy and paste this exact shell script class and I'll rename it as because I'm going to copy most of the content from that class so that's the reason I'm doing copy paste send file to Unix server great now let me open it if you are more if you are watching this video alone if you are not watched my previous video you need to go back to my previous video where I talked about how you can handle authentication and two other things you need to watch them then only you can understand this fine so let me start so the very first thing this private key I need this because I need to do that authentication so this is where I'm doing the authentication is in my private key that's what I need then I'm creating the session by using my username my host and my port yes I do not need password because I'm using a key then I'm setting a pass sorry properties basically with strict host post key checking to know in order not not the host ask me a password again and again then I need some changes from here so we were dealing with exact operation execute operation that could be your shell script execution that could be your any command execution that was exact but in this case the operation which I'm going to talk is about sending the file to Unix server so whether that is that could be sending file to your unique server or the same file to your unique server from your unique server my operation will be accept tp operation right so so in this case I should use my open channel in accept tp mode okay and so here since I was using exec operation over here I was using channel exec right but in this case I need to use channel accept tp okay so let me change it to channel SF tp okay and I think I need to import it let me import it explicitly so instead of channel exec I need to use channel SF channel SF tp yeah this is the one fine so now okay and can you see channel SF tp doesn't accept the command as set command right so that's the reason it is giving me error that's fine we'll look out what and all methods it has so what and all methods it has okay so let us go to methods I can see some versions that set file name I can see the operations like RM directory or RM or rename real path fit pwd put and get okay so basically sending file is nothing but it is my put operation I'm going to put my file onto the server right so this is my put operation basically okay so what what I need so I need to put my source let me go from start okay so I'm going to pass basically two parameters so first is my source and another one is my destination okay so here you can see this method particular particularly this method put string source and string destination so this is the method which I'm going to use okay so what is my source source is nothing but the file which I'm going to send okay so let me check if I have any okay so let me do the next four testers and let us say okay give me a second let me okay let me go to G drive and okay so here I have some file called as file to upload okay so let us say I'm going to upload this specific file let me copy it as a path and that could that should be my source in this case so it should be double slash five and what is my destination okay so my destination let us see my destination path and destination path is from your unique server so my destination path is let us say home and so that could be your any destination server where you want to send it fine so I don't want this okay let me use SFTP okay it doesn't accept that's when I don't need it anyway okay now let me try simply executing this okay and before that let me go to my server and let me do ls if if the file is existing okay so what file I'm going to send I'm trying to send file to upload and I don't see any file any such a file over here great let me execute I'm just saying there are some errors what are those errors well I don't see an error over here let me give me a second let me fix this okay so actually I had a problem with my JRE I recently upgraded my JRE and didn't set it in my current project so that was the issue fine so I okay and also I did couple of I did couple of messages okay I'll just show you so what I'm trying to do is I'm trying to connect a session from the session I have opened channel and as I said I'm going to use SFTP then I connected to the channel and then by using channel SFTP I just typecasted this channel to channel SFTP forcefully and by using that so that I can use one method on channel SFTP channel as a put method so I've shown you like we have some get method put method various overridden put method get methods okay so that's it simply I'm doing that okay so input method it is my source file so this is the file which I want to send to the host server and this is my host server location that is my unit server location where I should send this particular file okay and then what I'm trying to do is I'm trying to do if my SFTP is not equal to null okay then I'm trying to exit the SFTP session and finally I'm trying to disconnect the channel and disconnect the session fine so basically you can get this code on my github repository I'll share the link of my github repository so I have code for all the basically programs what I'm coding on my github repository fine now let me quickly execute this program and okay now you can see my execution is completed and SFTP so these are some error so messages so added by me so now we should see the file existing on the server which we're trying to send and yes it is file to upload.txt so this is the file which we were trying to send file to upload.txt okay so this is how we can send the file from my local machine to the Linux server so this is my source file name and this is my destination location where you want to send it so basically you need to parameterize these things based on your project requirements okay so what and all things you need to parameterize if you have your private key path then that is something which you need to parameterize if you have a password then again that is something you need to parameterize then your session sorry your username your post and your port these are the three things you need to parameterize and again your source file and destination path so these are the five six things you need to parameterize in order to make maintenance of your project easier in near life time okay so this is how basically you can send the file to the Linux server and that is what my objective of this current video was send or upload file to the Linux server so just the difference was as compared to my last video the difference was earlier I was using exact but this time since it is a file transfer operation so I'm using SFTP and I just forcefully typecasted this channel to channel SFTP so that this channel will act as a SFTP medium for doing the file transfer and then I have some methods put method by using a source file I am sending it to destination file so that's pretty simple okay so that's it I have for this video in my next video I'll talk the reverse thing that is how we can get the file from Unix server or how we can download the file from your Unix server to my local machine okay so stay still thank you hello welcome back welcome to the course of Unix for testers in this video I'm going to show you how we can upload or send multiple files to Unix or Linux server using a JSC which is a Java SSH library which can be used to interact with your Unix or Linux server from your Java code okay so okay so basically in my previous videos if you remember I talked about how you can send a single file by using put command okay so we can use some put command on SFTP object okay so we do something like SFTP.put followed by your source file name and destination name my destination name is my Unix directory okay so on the similar line we can perform the operation like sending multiple files or uploading multiple files from the directory to your Unix or Linux server so here I'm not going to write a complete code but I'll just tell you some logic how you can write