User:Ikrustok: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Ikrustok (talk | contribs)
No edit summary
Ikrustok (talk | contribs)
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Quest lahendus 11 - Skript paki installi kontrolliks ==
== Quest lahendus 11 - Skript paki installi kontrolliks [Bash] ==


<source lang="bash">
<source lang="bash">
Line 16: Line 16:


</source>
</source>
== Quest lahendus 38 skript etteantud faili muutmisaega [Bash] ==


<source lang="bash">
#!/bin/bash
#Autor: Ivar Krustok A22, ikrustok@itcollege.ee
#Version: 1
#Luua skript, mis muuda etteantud faili muutmisaega
fail=$1
if [ -f $fail ]
then
    echo "Sisesta faili uus kuup2ev kujul! (yyyymmdd)"
    read date
    echo "Sisesta faili uus muutmiskellaaeg! (hhss)"
    read kell
    `touch -mt ${date}${kell} ${fail}`
fi
</source>
== Skript paki installi kontrolliks [Python] ==


<source lang="python">
<source lang="python">
#!/usr/bin/python
#!/usr/bin/python
#Autor: Ivar Krustok A22, ikrustok@itcollege.ee
#Autor: Ivar Krustok A22, ikrustok@itcollege.ee
#Version: 1
#Version: 1.2
#Skript paki installi kontrolliks,kui puudub pakub sul installida
#Skript paki installi kontrolliks,kui puudub pakub sul installida
import os, subprocess
import os, subprocess
Line 51: Line 73:
else:
else:
print "Olgu, head aega siis!"
print "Olgu, head aega siis!"
</source>
== Skript emaili domeeni info saamiseks [Powershell] ==
<source lang="powershell">
#Autor: Ivar Krustok A22, ikrustok@itcollege.ee
#Version: 1.0
#skript, mis küsib emaili, eraldab sellest user ja domaini, uurib välja domaini ip aadressi, kas kodukas on üleval ja mis aadressil,
#prindib selle arvutikasutaja folderisse txt faili koos kellajaga millal küsiti ja domaini nimega.
$email = Read-Host “Mis su e-maili aadress on?”
$kasutaja = [Environment]::UserName
$atpos = $email.IndexOf(“@”)
$user = $email.substring(0,$atpos)
$domain = $email.substring($atpos+1, $email.length-($atpos+1))
Write-Host (“Username: “ + $user)
Write-Host (“Domain: “ + $domain)
$webRequest = [net.WebRequest]::Create("http://www.$domain")
$web = $webrequest.GetResponse();
$fol = [IO.Directory]::CreateDirectory("C:\Users\$kasutaja\$user")
[System.Net.Dns]::GetHostAddresses("$domain") | select IPAddressToString | Out-file $fol\ipaadress.txt -append
$A = Get-Date | Out-file $fol\ipaadress.txt -append
$web | Format-Table StatusCode,ResponseUri,LastModified | Out-file $fol\ipaadress.txt -append
if ($email.IndexOf(“@”) -lt 0) {
Write-Host “Ei sobi selline aadress!”
} else {
Write-Host “Sobiv aadress!”
}
</source>
</source>

Latest revision as of 18:48, 30 May 2011

Quest lahendus 11 - Skript paki installi kontrolliks [Bash]

#!/bin/bash
#Autor: Ivar Krustok A22, ikrustok@itcollege.ee
#Version: 2
#Skript paki installi kontrolliks
PAKK=$1
TARK=`/usr/bin/apt-cache policy $PAKK | grep Installed | awk '{print $2}'`
echo $TARK
if [ "$TARK" == "(none)" ]; then
        echo "0"
else
        echo "1"
fi

Quest lahendus 38 skript etteantud faili muutmisaega [Bash]

#!/bin/bash
#Autor: Ivar Krustok A22, ikrustok@itcollege.ee
#Version: 1
#Luua skript, mis muuda etteantud faili muutmisaega 


fail=$1
if [ -f $fail ]
then
    echo "Sisesta faili uus kuup2ev kujul! (yyyymmdd)"
    read date
    echo "Sisesta faili uus muutmiskellaaeg! (hhss)"
    read kell
    `touch -mt ${date}${kell} ${fail}`
fi

Skript paki installi kontrolliks [Python]

#!/usr/bin/python
#Autor: Ivar Krustok A22, ikrustok@itcollege.ee
#Version: 1.2
#Skript paki installi kontrolliks,kui puudub pakub sul installida
import os, subprocess
from apt import Cache
user = os.getuid()
if user != 0:
	print "Et programmi jooksutada pead olema root oigustega!", exit(1)
else:
	tark = raw_input("Tere palun sisesta programmi nimi, mida soovite kontrollida: ")
	devnull = open(os.devnull,"w")
	retval = subprocess.call(["dpkg","-s",tark],stdout=devnull,stderr=subprocess.STDOUT)
	devnull.close()
if retval != 0:
    print "Package", tark, "ei ole installitud."
else:
	print "Package", tark, "on juba installitud", exit(1)
kys = raw_input("Kas soovite seda programmi installida? [jah/ei]")
if kys == "jah":
	kys2 = raw_input("Olete te kindlad? [jah/ei]")
else:
	print "Head aega siis", exit(1)
if kys2 == "jah":
	try:
		cache = Cache()
		package = cache[tark]
    		package.mark_install(), cache.commit()
	except KeyError:
		print "Sellist programmi pole!"
else:
	print "Olgu, head aega siis!"

Skript emaili domeeni info saamiseks [Powershell]

#Autor: Ivar Krustok A22, ikrustok@itcollege.ee
#Version: 1.0
#skript, mis küsib emaili, eraldab sellest user ja domaini, uurib välja domaini ip aadressi, kas kodukas on üleval ja mis aadressil,
#prindib selle arvutikasutaja folderisse txt faili koos kellajaga millal küsiti ja domaini nimega.
$email = Read-Host Mis su e-maili aadress on?
$kasutaja = [Environment]::UserName
$atpos = $email.IndexOf(@)
$user = $email.substring(0,$atpos)
$domain = $email.substring($atpos+1, $email.length-($atpos+1))
Write-Host (Username:  + $user)
Write-Host (Domain:  + $domain)
$webRequest = [net.WebRequest]::Create("http://www.$domain")
$web = $webrequest.GetResponse();
$fol = [IO.Directory]::CreateDirectory("C:\Users\$kasutaja\$user")
[System.Net.Dns]::GetHostAddresses("$domain") | select IPAddressToString | Out-file $fol\ipaadress.txt -append
$A = Get-Date | Out-file $fol\ipaadress.txt -append
$web | Format-Table StatusCode,ResponseUri,LastModified | Out-file $fol\ipaadress.txt -append
if ($email.IndexOf(@) -lt 0) {
Write-Host Ei sobi selline aadress!
} else {
Write-Host Sobiv aadress!
}